Word/Access Automation

belsha

Registered User.
Local time
Today, 14:37
Joined
Jul 5, 2002
Messages
115
I am using the code below. I do not have any fields required at this time. If the user doesn't fill out a field, I get a type mismatch error. I would like to be able to say if CatID=13, then fill in the template with the text in OthTxt, but if OthTxt is null and CatID<>13, then ignore it and don't give the error message. I think an If/then statement would do it, but since the Word componant/library is involved I was not sure. Can anyone give a suggestion for the code to allow that? Thanks!

Private Sub cmdOpenWord_Click()
On Error GoTo Err_cmdOpenWord_Click

Dim oApp As Object
Dim strDocName As String
strDocName = " \\XXXXXX\YYY\ZZZ\XForm 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
.Item("Recom1").Range.Text = Recom1
.Item("Recom2").Range.Text = Recom2
.Item("Recom3").Range.Text = Recom3
.Item("OthTxt").Range.Text = OthTxt
.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
 
You could use an IF do that. But I'm not sure about the mismatch error, that could be your template.

eg

IF catID=13 then
.Item("OthTxt").Range.Text = OthTxt
end if
 

Users who are viewing this thread

Back
Top Bottom