J
James T.
Using Access 2002
I have used this code before, and it always worked. Now
for some reason it is not working. I am using it to merge
a record to a word doc that has bookmarks in it. If the
record field is empty, then it should bypass that bookmark
and go on to the next bookmark. When I run the merge, I am
getting an error and in looking at the code the error is
the first field without data.
The code at the botton where it tells it to put in "" if
there is no data is where it is hanging up on me.
Any help or suggestions appreciated.
Example:
Private Sub Command112_Click()
' start Microsoft Word.
Set wordApp = CreateObject("Word.Application")
With wordApp
' Make the application visible.
.Visible = True
' Open the document.
.Documents.Open ("path to word.doc")
' Move to each bookmark and insert text from the
form.
.ActiveDocument.Bookmarks("NamePg1").Select
.Selection.Text = (CStr(Forms!ApplicationInputForm!
NamePg1))
...etc...
End With
'''objWord.ActiveDocument.PrintPreview
wordApp.ActiveDocument.PrintOut Background:=False
wordApp.ActiveDocument.Close wdDoNotSaveChanges
wordApp.Quit wdDoNotSaveChanges
Set wordApp = Nothing
Exit Sub
Mergebuttonbutton_Err:
' If a field on the form is empty
' remove the bookmark text and continue.
If Err.Number = 94 Then
wordApp.Selection.Text = ""
Resume Next
End If
End Sub
I have used this code before, and it always worked. Now
for some reason it is not working. I am using it to merge
a record to a word doc that has bookmarks in it. If the
record field is empty, then it should bypass that bookmark
and go on to the next bookmark. When I run the merge, I am
getting an error and in looking at the code the error is
the first field without data.
The code at the botton where it tells it to put in "" if
there is no data is where it is hanging up on me.
Any help or suggestions appreciated.
Example:
Private Sub Command112_Click()
' start Microsoft Word.
Set wordApp = CreateObject("Word.Application")
With wordApp
' Make the application visible.
.Visible = True
' Open the document.
.Documents.Open ("path to word.doc")
' Move to each bookmark and insert text from the
form.
.ActiveDocument.Bookmarks("NamePg1").Select
.Selection.Text = (CStr(Forms!ApplicationInputForm!
NamePg1))
...etc...
End With
'''objWord.ActiveDocument.PrintPreview
wordApp.ActiveDocument.PrintOut Background:=False
wordApp.ActiveDocument.Close wdDoNotSaveChanges
wordApp.Quit wdDoNotSaveChanges
Set wordApp = Nothing
Exit Sub
Mergebuttonbutton_Err:
' If a field on the form is empty
' remove the bookmark text and continue.
If Err.Number = 94 Then
wordApp.Selection.Text = ""
Resume Next
End If
End Sub