VBA Access code to send data to MS Word Text Box (ActiveX control)

By Jee-ar ·
Anybody can correct my string? It cannot send data to MS Word Text Box (ActiveX). Thanks in advance.
Private Sub cmdSCIDFront_Click()
Dim appword As Word.Application
Dim doc As Word.Document
Dim Path As String

On Error Resume Next
Path = "C:\Users\DSWD-pc664\Documents\MSWDO\Services\AICS\2018\AICS\SC ID\SC ID Front - Copy.docx"
Set appword = GetObject(, "word.application")
If Err.Number <> 0 Then
Set appword = New Word.Application
appword.Visible = True
End If
Set doc = appword.Documents.Open(Path, , True)
With doc
.Boxes("txtFullName").Result = Me.SCFirstName & " " & Me.SCMiddleName & " " & Me.SCLastName
.Boxes("txtBarangay").Result = Me.SCBarangay
.Boxes("txtDateOfBirth").Result = Format(Me.SCDateOfBirth, "mmm-dd-yyyy")
If Me.SCSex = "Male" Then
.Boxes("txtSex").Result = "M"
ElseIf Me.SCSex = "Female" Then
.Boxes("txtSex").Result = "F"
End If
.Boxes("txtAge").Result = Fix((DateDiff("d", Me.SCDateOfBirth, Now) / 365.25))
.Boxes("txtDateIssued").Result = Format(Me.SCDateIssued, "mmm-dd-yyyy")
End With

appword.Visible = True

Set doc = Nothing
Set appword = Nothing
End Sub

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Share your knowledge

Related Discussions

Related Forums