Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Mail Merge with Word Problem
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00712811
Message ID:
00713054
Views:
14
I would recommend to record a macro in Word, then open macro for editing. From there you should see the exact connection string and other code you need.

>I am attempting to open a previously created word 2000 mail merge document and then automate the merge. I am using windows 2000, vfp6 sp5 and Office 2000 sr1 sp2.
>
>So I have this to open the document...
>
>oWord = getobject("", "Word.Application")
>oWord.visible = .t.
>lcFileName = alltrim(v_letters.le_path) && document to open
>lnConfirmConversions = 0
>lnReadOnly = 0
>lnAddToRecentFiles = 0
>lcPasswordDocument = ""
>lcPasswordTemplate = ""
>lnRevert = 0
>lcWritePasswordDocument	= ""
>lcWritePasswordTemplate	= ""
>
>oWord.Documents.Open(;
>		lcFileName,;
>		lnConfirmConversions,;
>		lnReadOnly,;
>		lnAddToRecentFiles,;
>		lcPasswordDocument,;
>		lcPasswordTemplate,;
>		lnRevert,;
>		lcWritePasswordDocument,;
>		lcWritePasswordTemplate )
>
>This opens up the document and I am able to see the layout of the address fields etc...
>
>Then I have this to try and open the data source and get just the record I need...
>
>lcDataFile = oApp.RootFolder + "\data\db.dbc" && full path to the database and the database name
>lcName = oApp.RootFolder + "\data\db.dbc"
>lnConfirmConversions = 0
>lnwdOpenFormatAuto = 0
>lnReadOnly = 0
>lnLinkToSource = 1
>lnAddToRecentFiles = 0
>lcPasswordDocument = ""
>lcPasswordTemplate = ""
>lnRevert = 0
>lcWritePasswordDocument	= ""
>lcWritePasswordTemplate	= ""
>lcConnection = "DSN=Visual FoxPro Database;UID=;PWD=;SourceDB=" + lcDataFile + ";SourceType=DBC;Exclusive=No;BackgroundFetch=Yes;Collate=MACHINE;Null=Yes;Deleted=Yes;"
>lcSQLStatement = "SELECT * FROM db!contacts WHERE Contacts.co_primary = ?vPrimary"
> oWord.ActiveDocument.MailMerge.OpenDataSource(;
>		lcName,;
>		lnwdOpenFormatAuto,;
>		lnConfirmConversions,;
>		lnReadOnly,;
>		lnLinkToSource,;
>		lnAddToRecentFiles,;
>		lcPasswordDocument,;
>		lcPasswordTemplate,;
>		lnRevert,;
>		lcWritePasswordDocument,;
>		lcWritePasswordTemplate,;
>		lcConnection,;
>		lcSQLStatement,;
>		lcSQLStatement1 )
>
>But it errors at this point with "OLE lDispatch exception code 0 from Microsoft Word: Word was unable to open the data source...
>
>I am sure I have the correct connection string because I have got it by returning Word.ActiveDocument.MailMerge.Datasource.connectionstring. Also If I comment the code the attempts to open the datasource and continue with the merge - the document merges perfectly to a new document but all records are merged.
>
>I have also tried to use .datasource.firstrecord and .datasource.lastrecord after locating the source record and getting it's recno() but it has proved very inconsistent.
>
>Any ideas were I am going wrong? I cannot bookmarks because the client does not want the blanks that bookmarks leave when there is no data in a field.
>
>Any help appreciated.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform