Hello,
I have a two part question..
I am trying to create reports using the Word Application vs. using Access reports. I grabbed some code off the internet and placed it on the "on click" command of a button, but received a "user not defined" error pointing to the "Dim appWord As Word.Application" portion of the code. Here is the code (with my fields):
Is there something wrong with this code?
Also, on the word document I've created, I am not sure if I have the fields linked right (don't know cause I haven't gotten the code above to work first). I selected INSERT>>FIELD>>FORMULA and typed in the names of the fields (i.e. =fldSubject). Is that right?
I have a two part question..
I am trying to create reports using the Word Application vs. using Access reports. I grabbed some code off the internet and placed it on the "on click" command of a button, but received a "user not defined" error pointing to the "Dim appWord As Word.Application" portion of the code. Here is the code (with my fields):
Code:
[/FONT][/COLOR]
[COLOR=black]Private Sub cmdPrint_Click()[/COLOR][COLOR=black][FONT=Courier New]
'Print customer slip for current customer.
Dim appWord 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("C:\WordForms\CustomerSlip.doc", , True)
With doc
.FormFields("fldRecipientOrganization").Result = Me!fldRecipientOrganization
.FormFields("fldRecipientDivision").Result = Me!fldRecipientDivision[/FONT][/COLOR][COLOR=black][FONT=Verdana][/FONT][/COLOR]
[COLOR=black].FormFields("fldRecipientAddress1").Result = Me!fldRecipientAddress1[/COLOR][COLOR=black][FONT=Courier New]
.FormFields("fldRecipientAddress2").Result = Me!fldRecipientAddress2[/FONT][/COLOR][COLOR=black][FONT=Verdana][/FONT][/COLOR]
[COLOR=black].FormFields("fldRecipientCityStateZip").Result = Me!fldRecipientCityStateZip[/COLOR][COLOR=black][FONT=Courier New]
.FormFields("fldSubject").Result = Me!fldSubject
.Visible = True
.Activate
End With
Set doc = Nothing
Set appWord = Nothing
Exit Sub
errHandler:
MsgBox Err.Number & ": " & Err.Description
End Sub[/FONT][/COLOR][COLOR=black][FONT=Verdana][/FONT][/COLOR]
[COLOR=black]
Is there something wrong with this code?
Also, on the word document I've created, I am not sure if I have the fields linked right (don't know cause I haven't gotten the code above to work first). I selected INSERT>>FIELD>>FORMULA and typed in the names of the fields (i.e. =fldSubject). Is that right?