#Define MYDBC _samples+"\DATA\testdata.DBC" #Define wdSendToEmail 2 #Define wdSendToFax 3 #Define wdSendToNewDocument 0 #Define wdSendToPrinter 1 #DEFINE wdDoNotSaveChanges 0 #DEFINE wdSaveChanges -1 cSQLStatement1 = "SELECT * FROM employee where title like [Sales%]" cSQLStatement2 = "" * Be carefull with where clause - where title = [Sales] fails * for ODBC uses ANSI SQL (exact match) * Two strings for first is limited to 255 chars Local llToPrinter oWordDocument=Createobject("word.application") && Create word object With oWordDocument .Documents.Add(Sys(5)+Curdir()+'mytemplate.dot') && Use a predefined template With .ActiveDocument.MailMerge .OpenDataSource(,,,.T.,,,,,,,, ; "DSN=Visual FoxPro Database;SourceDB="+MYDBC+; ";SourceType=DBC;Exclusive=No;",; cSQLStatement1, cSQLStatement2) && Open data source - Link to source If llToPrinter .Application.Options.PrintBackGround = .T. .Destination = wdSendToPrinter Else .Destination = wdSendToNewDocument Endif .Execute Endwith .Visible = !llToPrinter Endwith If llToPrinter oWatcher = CreateObject('myTimer') Read events endif Define Class myTimer As Timer Procedure Timer With oWordDocument If .BackgroundPrintingStatus > 0 && Wait printing to finish Return Endif For Each oDoc In .Documents oDoc.Close(wdDoNotSaveChanges) Endfor oDoc = .Null. .Quit(wdDoNotSaveChanges) EndWith this.Enabled = .F. Clear Events Endproc EnddefineCetin