J
Joe
Hi,
I am trying to use Word as a report writer via automation from
Access. I am trying to print an invoice that contains pre-defined
bookmarks. The code compiles and executes with no problem but when I
look at the finished document - there is no text printed at the
bookmarks as I intended. The text is not printed anywhere in the
document. I went into Word and verified that the bookmarks are there
and that I am using the correct bookmark names. My code is below.
Can anyone tell me what I am doing wrong?
Joe
---------------------------
Private Sub btnPrint_Click()
Dim wrdApp As Word.Application
' Create an instance of Word, and make it visible.
Set wrdApp = New Word.Application
wrdApp.Documents.Add Application.CurrentProject.Path & "\Customer
Invoice Master.dot"
wrdApp.Visible = True
With wrdApp.ActiveDocument.Bookmarks
.Item("BK_NAME").Range.Text = "Joe Smith"
.Item("BK_ADDRESS").Range.Text = "1234 Main Street"
End With
OutputFileName = "\Invoice" & "0001"
wrdApp.ActiveDocument.SaveAs CurrentProject.Path & OutputFileName
wrdApp.ActiveDocument.Close False
' Notify user we are done.
MsgBox "Invoice succesfully created!", vbMsgBoxSetForeground
' Release references.
Set wrdApp = Nothing
End Sub
I am trying to use Word as a report writer via automation from
Access. I am trying to print an invoice that contains pre-defined
bookmarks. The code compiles and executes with no problem but when I
look at the finished document - there is no text printed at the
bookmarks as I intended. The text is not printed anywhere in the
document. I went into Word and verified that the bookmarks are there
and that I am using the correct bookmark names. My code is below.
Can anyone tell me what I am doing wrong?
Joe
---------------------------
Private Sub btnPrint_Click()
Dim wrdApp As Word.Application
' Create an instance of Word, and make it visible.
Set wrdApp = New Word.Application
wrdApp.Documents.Add Application.CurrentProject.Path & "\Customer
Invoice Master.dot"
wrdApp.Visible = True
With wrdApp.ActiveDocument.Bookmarks
.Item("BK_NAME").Range.Text = "Joe Smith"
.Item("BK_ADDRESS").Range.Text = "1234 Main Street"
End With
OutputFileName = "\Invoice" & "0001"
wrdApp.ActiveDocument.SaveAs CurrentProject.Path & OutputFileName
wrdApp.ActiveDocument.Close False
' Notify user we are done.
MsgBox "Invoice succesfully created!", vbMsgBoxSetForeground
' Release references.
Set wrdApp = Nothing
End Sub