Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding data from access to a word document using bookmarks 1

Status
Not open for further replies.

terre

Technical User
Feb 2, 2003
97
AU
I am trying to add some data to a word document.

I found this code in FAQ, and it seems to work ok, but stops after adding only the first bookmark.

Dim dbs As Database
Dim objWord As Object

Set dbs = CurrentDb

Set objWord = CreateObject("Word.Application")

With objWord

.Visible = True
.Documents.Open (strDocPath)

.ActiveDocument.Bookmarks("ClientID").Select
.Selection.Text = (CStr(Forms!ClientDetails!AllocatedClientID))
.ActiveDocument.Bookmarks.Add ClientID, Range = Selection.Range

.ActiveDocument.Bookmarks("ClientName").Select
.Selection.Text = (CStr(Forms!ClientDetails!Auto_Title0))
.ActiveDocument.Bookmarks.Add ClientName, Range = Selection.Range

.ActiveDocument.Bookmarks("DoB").Select
.Selection.Text = (CStr(Forms!ClientDetails!DoB))
.ActiveDocument.Bookmarks.Add DoB, Range = Selection.Range

.ActiveDocument.Bookmarks("ClientAddress").Select
.Selection.Text = (CStr(Forms!ClientDetails!StreetAddress & ", " & Forms!ClientDetails!City & ", " & Forms!ClientDetails!State & " " & Forms!ClientDetails![Postal Code]))
.ActiveDocument.Bookmarks.Add ClientAddress, Range = Selection.Range

.ActiveDocument.Bookmarks("Telephone").Select
.Selection.Text = (CStr(Forms!ClientDetails!Mphone))
.ActiveDocument.Bookmarks.Add Telephone, Range = Selection.Range

End With

Set objWord = Nothing
Set dbs = Nothing


Can anyone tell me why it stops after adding the ClientID, and will not move on to ClientName?
Tells me that there is a missing object.

Thanks in advance

Tezza
PS. The bookmarks are in the header, but it doesn't work even if they are not.
 
Actually......"Object required
 
.ActiveDocument.Bookmarks.Add ClientID, Range[!]:[/!]= [!].[/!]Selection.Range

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV.
A step closer I think, but now gives the "Bad bookmark name." message.

I have checked, and the bookmarks are named exactly as in code above.

It still stops after adding the first bookmark.

Any suggestions?

Terre
 
.ActiveDocument.Bookmarks.Add "ClientID", Range:= .Selection.Range

Works!!

Thanks for your help, and support, the world is a better place for the support of you guys out there.

PHV in particular this time.

Terre
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top