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) & " " & Trim(txtLTPATL) & " on \\SHFIL\" & 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 = "Printed"
txtMedium.Refresh
StatusBar2.Panels(1).Text = "Finished PrintMergeLetter"
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.