Word Automation - type mismatch

belsha

Registered User.
Local time
Today, 17:46
Joined
Jul 5, 2002
Messages
115
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
 
Word Automation Continued Question

Using the code referred to in the prior post. I had to change the Word template which was a table containing 5 columns because the last column's text would overflow the box when printing, and would not just flow into the next page, it would push other parts onto the next page and leave the text of the last column on page 2 blank. Tried a page break,a section break , and no breaks at all, just the last column being moved onto another page. Get the following error message no matter what I tried -"This is not a valid action for the end of a row." Is there something I can use to move this column to a second page and not get a coding error? Thanks!
 

Users who are viewing this thread

Back
Top Bottom