Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2007

Tip: Looking for answers? Try searching our database.

Not able to jump to bookmark

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
KM - 21 Jun 2007 18:49 GMT
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
David Sisson - 21 Jun 2007 21:57 GMT
Try this method instead.

http://word.mvps.org/faqs/macrosvba/InsertingTextAtBookmark.htm

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.