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.
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.