>with thisform >local bolObjOk >* check the template >if !file(v_letters.le_path) then > messagebox(" Template not found... ", OKONLY + STOPICON + FIRSTBUTTON, oApp.ProdName) > return .t. >endif >* get the data for the merge >vPrimary = .pMainPrimary >* new code added 17.10.02 by cpm - mail merging with word using datasource and mail >* merge templates > >** Mail merge Letter/Label file >** Mail merge Data Source file >bolObjOk = .t. >* on error bolObjOk = .F. > >oWord = getobject("", "Word.Application") >APPLICATION.OLERequestPendingTimeout = 0 >if type("oWord.Name") <> "C" > messagebox(" Unable to perform the Mail Merge... ", OKONLY + STOPICON + FIRSTBUTTON, oApp.ProdName) > return .t. >endif > >lcFileName = alltrim(v_letters.le_path) >lnConfirmConversions = 0 >lnReadOnly = 0 >lnAddToRecentFiles = 0 >lcPasswordDocument = "" >lcPasswordTemplate = "" >lnRevert = 0 >lcWritePasswordDocument = "" >lcWritePasswordTemplate = "" > >oWord.visible = .t. > >if bolObjOk > oWord.Documents.Open(; > lcFileName,; > lnConfirmConversions,; > lnReadOnly,; > lnAddToRecentFiles,; > lcPasswordDocument,; > lcPasswordTemplate,; > lnRevert,; > lcWritePasswordDocument,; > lcWritePasswordTemplate ) >endif > >lcDataFile = oApp.RootFolder + "\data\youthbase.dbc" >lcName = oApp.RootFolder + "\data\youthbase.dbc" >lnConfirmConversions = 0 >lnwdOpenFormatAuto = 0 >lnReadOnly = 0 >lnLinkToSource = 1 >lnAddToRecentFiles = 0 >lcPasswordDocument = "" >lcPasswordTemplate = "" >lnRevert = 0 >lcWritePasswordDocument = "" >lcWritePasswordTemplate = "" > >* connection string >lcConnection = "DSN=Visual FoxPro Database;UID=;PWD=;SourceDB=" + lcDataFile + ";SourceType=DBC;Exclusive=No;BackgroundFetch=Yes;Collate=MACHINE;Null=Yes;Deleted=Yes;" >lcSQLStatement = "SELECT * FROM youthbase!contacts LEFT OUTER JOIN youthbase!addresses ON Contacts.co_primary == Addresses.ad_parent WHERE Contacts.co_primary == " + alltrim(str(vPrimary)) + " AND Addresses.ad_default == 1" >lcSQLStatement1 = "" > >* >**************** error occurs here ******************************* >* >if bolObjOk > oWord.ActiveDocument.MailMerge.OpenDataSource(; > lcName,; > lnwdOpenFormatAuto,; > lnConfirmConversions,; > lnReadOnly,; > lnLinkToSource,; > lnAddToRecentFiles,; > lcPasswordDocument,; > lcPasswordTemplate,; > lnRevert,; > lcWritePasswordDocument,; > lcWritePasswordTemplate,; > lcConnection,; > lcSQLStatement,; > lcSQLStatement1 ) >endif > >if bolObjOk > With oWord.ActiveDocument.MailMerge > .Destination = 0 && to new file... > .MailAsAttachment = 0 > .MailAddressFieldName = "" > .MailSubject = "" > .SuppressBlankLines = 1 > .Execute(0) > EndWith >endif > >on error > >* end of new mail merge code >endwith >>