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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Merging from word to access with bookmarks

Status
Not open for further replies.

oggsta

Technical User
Jun 22, 2002
41
GB
When i use the following script to merge from access in to a word document it works fine when i merge from the one table from access. i.e (CStr(Forms!sheet1!Client))

However when i try and use two tables from access and add (CStr(Forms!main!Clientname))the script does not work and the word documnet halts at this point,

Any suggustions as to why this occurs would be appreciated.


With objWord
'Make the application visible.
.Visible = True

'Open the document.
.Documents.Open ("\\Linux\Planning\Planning\Informationplanning\Templates\Crowncastle\databasemerge\DCF1.doc")

'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("Client").Select
.Selection.Text = (CStr(Forms!sheet1!Client))
.ActiveDocument.Bookmarks("Region").Select
.Selection.Text = (CStr(Forms!sheet1!Region))
.ActiveDocument.Bookmarks("feereburse").Select
.Selection.Text = (CStr(Forms!sheet1!feereburse))
.ActiveDocument.Bookmarks("Clientname").Select
.Selection.Text = (CStr(Forms!Main!Clientname))


End With

Set objWord = Nothing
Exit Sub

MergeButton_Err:
'If a field on the form is empty, remove the bookmark text, and
'continue.
If Err.number = 94 Then
objWord.Selection.Text = ""
Resume Next

'If the Photo field is empty.
ElseIf Err.number = 2046 Then
MsgBox "Please add a photo to this record and try again."
Else
MsgBox Err.number & vbCr & Err.Description
End If
Else
MsgBox "Please enter a fee and the DCF date and try again", vbOKOnly + vbInformation
End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top