In the following code, I get a "type mismatch" error when the field in the database is blank and the Word Bookmark has nothing to pull from for a specific record. Is there some error handling code I can use to say if any specific field is blank in the database, go on to the next field without giving an error?
Private Sub cmdOpenWord_Click()
On Error GoTo Err_cmdOpenWord_Click
Dim oApp As Object
Dim strDocName As String
strDocName = " \\X\Trial\Peer Review Final Bookmarked.dot"
Set oApp = CreateObject("Word.Application")
oApp.Visible = True 'Make the application visible
oApp.WindowState = wdWindowStateMaximize 'Maximize the Word Window
With oApp
oApp.Documents.Open strDocName 'Open the Word Template containing bookmarks
End With
With oApp.ActiveDocument.Bookmarks 'Using the info in the Access form, populate the template
.Item("RevDate").Range.Text = RevDate
.Item("ClinID").Range.Text = ClinID
.Item("ProvCd").Range.Text = ProvCd
.Item("CaseNo").Range.Text = CaseNo
.Item("CsFir").Range.Text = CsFir
.Item("CsLast").Range.Text = CsLast
.Item("MRNo").Range.Text = MRNo
.Item("DOS").Range.Text = DOS
.Item("ReasID").Range.Text = ReasID
.Item("ConcID").Range.Text = ConcID
End With
oApp.ActiveDocument.PrintOut Background:=False
oApp.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
oApp.Quit
Set oApp = Nothing
Exit_cmdOpenWord_Click:
Exit Sub
Err_cmdOpenWord_Click:
MsgBox Err.Description
Resume Exit_cmdOpenWord_Click
End Sub
Private Sub cmdOpenWord_Click()
On Error GoTo Err_cmdOpenWord_Click
Dim oApp As Object
Dim strDocName As String
strDocName = " \\X\Trial\Peer Review Final Bookmarked.dot"
Set oApp = CreateObject("Word.Application")
oApp.Visible = True 'Make the application visible
oApp.WindowState = wdWindowStateMaximize 'Maximize the Word Window
With oApp
oApp.Documents.Open strDocName 'Open the Word Template containing bookmarks
End With
With oApp.ActiveDocument.Bookmarks 'Using the info in the Access form, populate the template
.Item("RevDate").Range.Text = RevDate
.Item("ClinID").Range.Text = ClinID
.Item("ProvCd").Range.Text = ProvCd
.Item("CaseNo").Range.Text = CaseNo
.Item("CsFir").Range.Text = CsFir
.Item("CsLast").Range.Text = CsLast
.Item("MRNo").Range.Text = MRNo
.Item("DOS").Range.Text = DOS
.Item("ReasID").Range.Text = ReasID
.Item("ConcID").Range.Text = ConcID
End With
oApp.ActiveDocument.PrintOut Background:=False
oApp.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
oApp.Quit
Set oApp = Nothing
Exit_cmdOpenWord_Click:
Exit Sub
Err_cmdOpenWord_Click:
MsgBox Err.Description
Resume Exit_cmdOpenWord_Click
End Sub