M
Meryl
I have an event procedure to create a mailing address in
Word from my form using bookmarks in Word. The mailing
address is for doctors, where not all the fields may have
values. For instance, some doctors work at a hospital
and others don't, some have a floor or suite #, other's
don't.
If a field has a null value, then I get a "type mismatch"
error message and none of the remaining bookmarks are
filled in in Word. Is there some way to code for this?
Below is my current code. Thank you for your help!
Private Sub AddressLabelProf_Click()
On Error GoTo Err_AddressLabelProf_Click
Dim oApp As Object
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
oApp.Documents.Add "C:\Windows\Application
Data\Microsoft\Templates\AddressLabelProf.dot"
oApp.Visible = True
' The following code is generated from your Access form
while it is
' manipulating an instance of Word.
' So, while it looks somewhat like VBA, it's really Word
VBA.
If oApp.ActiveDocument.Bookmarks.Exists("FirstName") =
True Then
oApp.ActiveDocument.Bookmarks("FirstName").Range.Text
= Me![First Name]
End If
If oApp.ActiveDocument.Bookmarks.Exists("LastName") =
True Then
oApp.ActiveDocument.Bookmarks("LastName").Range.Text
= Me![Last Name]
End If
If oApp.ActiveDocument.Bookmarks.Exists("Address1") =
True Then
oApp.ActiveDocument.Bookmarks("Address1").Range.Text
= Me![Mailing Address Line 1]
End If
If oApp.ActiveDocument.Bookmarks.Exists("Floor") = True
Then
oApp.ActiveDocument.Bookmarks("Floor").Range.Text =
Me![Suite/Floor]
End If
If oApp.ActiveDocument.Bookmarks.Exists("Address2") =
True Then
oApp.ActiveDocument.Bookmarks("Address2").Range.Text
= Me![Mailing Address Line 2]
End If
If oApp.ActiveDocument.Bookmarks.Exists("City") = True
Then
oApp.ActiveDocument.Bookmarks("City").Range.Text = Me!
City
End If
If oApp.ActiveDocument.Bookmarks.Exists("State") = True
Then
oApp.ActiveDocument.Bookmarks("State").Range.Text =
Me![State Code]
End If
If oApp.ActiveDocument.Bookmarks.Exists("Zip") = True
Then
oApp.ActiveDocument.Bookmarks("Zip").Range.Text = Me!
[Postal Code]
End If
Exit_AddressLabelProf_Click:
Exit Sub
..
Word from my form using bookmarks in Word. The mailing
address is for doctors, where not all the fields may have
values. For instance, some doctors work at a hospital
and others don't, some have a floor or suite #, other's
don't.
If a field has a null value, then I get a "type mismatch"
error message and none of the remaining bookmarks are
filled in in Word. Is there some way to code for this?
Below is my current code. Thank you for your help!
Private Sub AddressLabelProf_Click()
On Error GoTo Err_AddressLabelProf_Click
Dim oApp As Object
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
oApp.Documents.Add "C:\Windows\Application
Data\Microsoft\Templates\AddressLabelProf.dot"
oApp.Visible = True
' The following code is generated from your Access form
while it is
' manipulating an instance of Word.
' So, while it looks somewhat like VBA, it's really Word
VBA.
If oApp.ActiveDocument.Bookmarks.Exists("FirstName") =
True Then
oApp.ActiveDocument.Bookmarks("FirstName").Range.Text
= Me![First Name]
End If
If oApp.ActiveDocument.Bookmarks.Exists("LastName") =
True Then
oApp.ActiveDocument.Bookmarks("LastName").Range.Text
= Me![Last Name]
End If
If oApp.ActiveDocument.Bookmarks.Exists("Address1") =
True Then
oApp.ActiveDocument.Bookmarks("Address1").Range.Text
= Me![Mailing Address Line 1]
End If
If oApp.ActiveDocument.Bookmarks.Exists("Floor") = True
Then
oApp.ActiveDocument.Bookmarks("Floor").Range.Text =
Me![Suite/Floor]
End If
If oApp.ActiveDocument.Bookmarks.Exists("Address2") =
True Then
oApp.ActiveDocument.Bookmarks("Address2").Range.Text
= Me![Mailing Address Line 2]
End If
If oApp.ActiveDocument.Bookmarks.Exists("City") = True
Then
oApp.ActiveDocument.Bookmarks("City").Range.Text = Me!
City
End If
If oApp.ActiveDocument.Bookmarks.Exists("State") = True
Then
oApp.ActiveDocument.Bookmarks("State").Range.Text =
Me![State Code]
End If
If oApp.ActiveDocument.Bookmarks.Exists("Zip") = True
Then
oApp.ActiveDocument.Bookmarks("Zip").Range.Text = Me!
[Postal Code]
End If
Exit_AddressLabelProf_Click:
Exit Sub
..