I am trying to create reports using the Word Application vs. using Access reports.
For some reason, it doesn't bring up the Word Document unless I click the button twice (the code is in the "On Click" portion).
Also, the fields aren't populating with the data.
Any idea why?
[/COLOR]
For some reason, it doesn't bring up the Word Document unless I click the button twice (the code is in the "On Click" portion).
Also, the fields aren't populating with the data.
Any idea why?
Code:
[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[COLOR=black][FONT=Courier New]Private Sub cmdPrint_Click()[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]'Print customer slip for current customer.[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]Dim appWord As Word.Application[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]Dim doc As Word.Document[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]'Avoid error 429, when Word isn't open.[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]On Error Resume Next[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]Err.Clear[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]'Set appWord object variable to running instance of Word.[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]Set appWord = GetObject(, "Word.Application")[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]If Err.Number <> 0 Then[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]'If Word isn't open, create a new instance of Word.[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]Set appWord = New Word.Application[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]End If[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]Set doc = appWord.Documents.Open("C:\WordForms\CustomerSlip.doc", , True)[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]With doc[/FONT][/COLOR]
[COLOR=black][FONT=Courier New].FormFields("fldRecipientOrganization").Result = Me!fldRecipientOrganization[/FONT][/COLOR]
[COLOR=black][FONT=Courier New].FormFields("fldRecipientDivision").Result = Me!fldRecipientDivision[/FONT][/COLOR]
[COLOR=black][FONT=Courier New].FormFields("fldRecipientAddress1").Result = Me!fldRecipientAddress1[/FONT][/COLOR]
[COLOR=black][FONT=Courier New].FormFields("fldRecipientAddress2").Result = Me!fldRecipientAddress2[/FONT][/COLOR]
[COLOR=black][FONT=Courier New].FormFields("fldRecipientCityStateZip").Result = Me!fldRecipientCityStateZip[/FONT][/COLOR]
[COLOR=black][FONT=Courier New].FormFields("fldSubject").Result = Me!fldSubject[/FONT][/COLOR]
[COLOR=black][FONT=Courier New].Visible = True[/FONT][/COLOR]
[COLOR=black][FONT=Courier New].Activate[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]End With[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]Set doc = Nothing[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]Set appWord = Nothing[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]Exit Sub[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]errHandler:[/FONT][/COLOR]
[COLOR=black][FONT=Courier New]MsgBox Err.Number & ": " & Err.Description[/FONT][/COLOR]
[COLOR=black][SIZE=3][FONT=Times New Roman]End Sub[/FONT][/SIZE][/COLOR]
[COLOR=black][FONT=Times New Roman][SIZE=3]