I am using the code below to automate the filling in and printing out of a Word template from Access 97.  I have run into a problem whereby if any field is left blank, I get a type mismatch error.  The minute the field is filled in with anything, the error is gone.  I would like to insert some If statements to say If ReasID=2 then    .Item("SelCsSp").Range.Text = SelCsSp 
Else .Item("SelCsSp").Range.Text = "".
In addition, I would like to say If ReasID=13 then
.Item("OthTxt").Range.Text = OthTxt
Else .Item("OthTxt").Range.Text = ""
In other words, If someone chooses reason 2, print out the SelCsSP field, if not leave it blank. However, if you leave it blank (tried this already), you get the type mismatch error. And any choices <> 2 or <>13 should have neither field (SelCsSP or OthTxt) print. Can someone show me in my code where to put the statements needed, or if they should go somewhere else?
Thanks!!
Private Sub cmdOpenWord_Click()
On Error GoTo Err_cmdOpenWord_Click
Dim oApp As Object
Dim strDocName As String
strDocName = " \\X\Y$\A\Final.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("SelCsSp").Range.Text = SelCsSp
           
.Item("OthTxt").Range.Text = OthTxt
               
.Item("ConcID").Range.Text = ConcID
.Item("Recom1").Range.Text = Recom1
.Item("Recom2").Range.Text = Recom2
.Item("Recom3").Range.Text = Recom3
.Item("DesDisc").Range.Text = DesDisc
.Item("Desc").Range.Text = Desc
    
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
 Else .Item("SelCsSp").Range.Text = "".
In addition, I would like to say If ReasID=13 then
.Item("OthTxt").Range.Text = OthTxt
Else .Item("OthTxt").Range.Text = ""
In other words, If someone chooses reason 2, print out the SelCsSP field, if not leave it blank. However, if you leave it blank (tried this already), you get the type mismatch error. And any choices <> 2 or <>13 should have neither field (SelCsSP or OthTxt) print. Can someone show me in my code where to put the statements needed, or if they should go somewhere else?
Thanks!!
Private Sub cmdOpenWord_Click()
On Error GoTo Err_cmdOpenWord_Click
Dim oApp As Object
Dim strDocName As String
strDocName = " \\X\Y$\A\Final.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("SelCsSp").Range.Text = SelCsSp
.Item("OthTxt").Range.Text = OthTxt
.Item("ConcID").Range.Text = ConcID
.Item("Recom1").Range.Text = Recom1
.Item("Recom2").Range.Text = Recom2
.Item("Recom3").Range.Text = Recom3
.Item("DesDisc").Range.Text = DesDisc
.Item("Desc").Range.Text = Desc
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