Hi,
I have an Access 2003 database where I log in application requests. I have added a button that "should" allow me to populate a Word form based on the data entered. I searched the internet and found and modified code to accomplish this. Please forgive me as I am very new to VBA. The problem I am having it duplicate fields are not populated.
On the form I have Fname and Lname on every page. It only populates for the first page, the rest are blank.
How should I fix this? Below is the code I am using. Any help would be appreciated.
Private Sub cmdPrint_Click()
'Print Application Packet for Applicant.
Dim objWord As Word.Application
Dim doc As Word.Document
'Avoid error 429, when Word isn't open.
On Error Resume Next
Err.Clear
'Set appWord object variable to running instance of Word.
Set Appword = GetObject(, "Word.Application")
If Err.Number <> 0 Then
'If Word isn't open, create a new instance of Word.
Set Appword = New Word.Application
End If
Set doc = Appword.Documents.Open("S:\Application Packet w_ Cover Letter.doc", , True)
With doc
.FormFields("fldFirstName").Result = Me![FIRST NAME]
.FormFields("fldLastName").Result = Me![LAST NAME]
.FormFields("fldDegree").Result = Me!Degree
.FormFields("fldAddress").Result = Me!Address
.FormFields("fldCity").Result = Me!City
.FormFields("fldState").Result = Me!State
.FormFields("fldZip").Result = Me!Zip
.FormFields("fldGroupName").Result = Me![Group Name]
.Visible = True
.Activate
End With
Set doc = Nothing
Set Appword = Nothing
Exit Sub
errHandler:
MsgBox Err.Number & ": " & Err.Description
End Sub
I have an Access 2003 database where I log in application requests. I have added a button that "should" allow me to populate a Word form based on the data entered. I searched the internet and found and modified code to accomplish this. Please forgive me as I am very new to VBA. The problem I am having it duplicate fields are not populated.
On the form I have Fname and Lname on every page. It only populates for the first page, the rest are blank.
How should I fix this? Below is the code I am using. Any help would be appreciated.
Private Sub cmdPrint_Click()
'Print Application Packet for Applicant.
Dim objWord As Word.Application
Dim doc As Word.Document
'Avoid error 429, when Word isn't open.
On Error Resume Next
Err.Clear
'Set appWord object variable to running instance of Word.
Set Appword = GetObject(, "Word.Application")
If Err.Number <> 0 Then
'If Word isn't open, create a new instance of Word.
Set Appword = New Word.Application
End If
Set doc = Appword.Documents.Open("S:\Application Packet w_ Cover Letter.doc", , True)
With doc
.FormFields("fldFirstName").Result = Me![FIRST NAME]
.FormFields("fldLastName").Result = Me![LAST NAME]
.FormFields("fldDegree").Result = Me!Degree
.FormFields("fldAddress").Result = Me!Address
.FormFields("fldCity").Result = Me!City
.FormFields("fldState").Result = Me!State
.FormFields("fldZip").Result = Me!Zip
.FormFields("fldGroupName").Result = Me![Group Name]
.Visible = True
.Activate
End With
Set doc = Nothing
Set Appword = Nothing
Exit Sub
errHandler:
MsgBox Err.Number & ": " & Err.Description
End Sub