Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I 'catch'/respond to errors generated by Word?

Status
Not open for further replies.

PaulAH

Programmer
Oct 29, 2002
26
NZ
i've inherited a VB6 application that uses Word95 to generate letters (mail merge). Occasionally word will generate an error (for instance, the merge file doesn't contain the fields required by the document) which requires a response. However this application runs on an unmonitored server so no-one knows the app has stopped until we get dozens of complaints from users expecting their letters! Is there a way I can catch these messages and either skip the error (and move on to next letter request) or respond to the message from within the VB app?
 
Use the On Error statement to catch errors. You might reduce the frequency of errors if you set your database with default values, or converted Nulls to empty strings as you get your recordset

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Hi John,
The problem is Vb hasn't generated an error.
VB has instantiated a version of word and word has generated the error...meanwhile the Vb app is still waiting for word to complete...here's a copy of the code:
(fields such as txtLTPMNL have been retrieved earlier in the code)

'*=======================================================
'* Create a Mail Merged document and send it to a
'* printer
'*=======================================================

Dim WordDoc As Word.Document
Dim DBaseSQL As String
Dim DataSource As String
Dim iCopies As Integer

On Error GoTo WordErrorTrap

StatusBar2.Panels(1).Text = "Started PrintMergeLetter..."
DBaseSQL = "SELECT * FROM " & txtLTPMNL
Set WordDoc = WordApp.Documents.Open(MasterDirectory & txtLTMASL)
' Set WordDoc = GetObject(MasterDirectory & txtLTMASL)
' Set WordApp = WordDoc.Application
DataSource = "DSN=dBase Files;DBQ=" & MergeDirectory & ";FIL=dBase4;"

'set up and perform the mailmerge operation

Dim wMail As Word.MailMerge
Set wMail = WordDoc.MailMerge

wMail.OpenDataSource Name:=MergeDirectory & txtLTPMNL, Connection:=DataSource, sqlstatement:=DBaseSQL

With wMail
.Destination = wdSendToNewDocument
.SuppressBlankLines = False
.DataSource.FirstRecord = 1
.DataSource.LastRecord = 1
.Execute
End With

If IsNumeric(txtLTCOPL) Then
iCopies = CInt(txtLTCOPL)
If iCopies < 1 Then iCopies = 1
Else
iCopies = 1
End If

'set the printer
WordApp.ActivePrinter = Trim(txtLTPDRL) & &quot; &quot; & Trim(txtLTPATL) & &quot; on \\SHFIL\&quot; & Trim(txtLTPATL)
WordApp.PrintOut , , , , , , , iCopies
Sleep 2000 'allows word to complete printing

CloseDocuments WordApp 'close all the open documents
Set WordDoc = Nothing
Set wMail = Nothing

txtMedium.Text = &quot;Printed&quot;
txtMedium.Refresh
StatusBar2.Panels(1).Text = &quot;Finished PrintMergeLetter&quot;
Exit Sub

WordErrorTrap:

'** error handling code here but never executed in scenario

' on executing Wordapp.Printout word generates a document by mailmerge using the specified documentr and merge file. Howevere sometime the merge file fields don't match the merge fields in the document and word displays an error dialog box and waits for a reply. meanwhile the VB app is hanging, waiting for word to complete the process.
 
Sorry I assumed from the question that you were doing the mailmerge in VB, rather than in Word. I didn't do much with Word97 Mailmerge, so I can't help further

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top