Not able to jump to bookmark

K

KM

Hello !

I want to generate an automated invoice in Word with data from Access.
VBA in Access triggers the function, calls Word and should jump to
certain bookmarks and enter text. (please see the code fragments
below)

Jumping to bookmarks works perfectly well in Word and with Word
macros. But calling the code from Access returns several errors when
trying to jump to a bookmark. Everything else (entering text, etc.)
works !

The errors tell me "Runtime error 5102" and "Runtime error 5101".

Would be great if anyone could help me with this issue ! Thanks in
advance !

Best,

Konstantin




Here is the code: (it's not finished yet !)


Sub CreateInvoice(company_id As Integer, date_start As Date, date_end
As Date)

Dim db As Database
Dim wdobj As Object

Dim rst As Recordset
Dim sqlCompanyAddress As String

Set db = CurrentDb()
Set wdobj = CreateObject("word.application")

With wdobj
.Visible = True
.Documents.Add Template:="C:\Templates\Invoice.dot", _
NewTemplate:=False, DocumentType:=0

sqlCompanyAddress = "SELECT " & _
"tblCompany.Company, tblAddress.Department,
tblAddress.Street, " & _
"tblAddress.PostCode, tblAddress.City, tblCountry.Name " &
_
"FROM tblCountry INNER JOIN " & _
"(tblCompany INNER JOIN tblAddress ON tblCompany.ID =
tblAddress.Company_ID) " & _
"ON tblCountry.ID = tblAddress.Country_ID " & _
"WHERE (((tblAddress.BillingAddress)=True))"


Set rst = db.OpenRecordset(sqlCompanyAddress)

.selection.Goto What:=wdGoToBookmark, Name:="address"
.selection.TypeText rst!company & Chr(13) & rst!Department &
Chr(13) & rst!Street & _
Chr(13) & Chr(13) & rst!PostCode & " " & rst!City
If rst!Name <> "Deutschland" Then
.selection.TypeText = Chr(13) & rst!Name
End If

End With

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top