Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Mail Merge to Word from VFP gives OLE IDispatch Error
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00725725
Message ID:
00725732
Views:
10
Seems you need to correct syntax as below. Also just in case try to avoid unneccesary parameters:

...OpenDataSource(lcName,,,,,,,,,,,;
lcConnection + 'SQLStatement:= "'+lcSQLStatement+'"')


>Any help appreciated!!!
>
>We have a VFP6 SP5 application - a contacts database on our Windows 2000 Server box - one feature of the app enables the production of a letter to a single contact when a button is pressed on the contacts record.
>
>The document is first created with Microsoft Word 2000 SP2 by using the Mail Merge Wizard and connecting to the VFP dbc via the Microsoft Visual Foxpro Driver. The document is then saved in a folder in the root directory of the app. In the app we have an "Add Template" form where we can then pick up the template for use. We have MDAC 2.6 installed on Windows 2000 workstations.
>
>At our offices this works perfectly OK - but at our clients office we get this error message when the app tries to open the datasource... "OLE IDispatch Exception Code 0 from Microsoft Word. Microsoft Word was unable to open the data source."
>
>The environment is the same - Windows 2000 server box with Win 2000 workstations, Office 2000 service packed to SP2. Same hub.
>
>Here is the code that does the merge...
>
>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
>
>
>I have indicated in the code with a comment as to where it errors.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform