Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Attaching datasource to Word XP
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00709221
Message ID:
00709227
Views:
16
Lee,

You need to change the OpenDataSource to use the old Word200 method.
#define wdMergeSubTypeWord2000	8

oWord.ActiveDocument.MailMerge.OpenDataSource(;
				lcName,;
				lnwdOpenFormatAuto,;
				lnConfirmConversions,;
				lnReadOnly,;
				lnLinkToSource,;
				lnAddToRecentFiles,;
				lcPasswordDocument,;
				lcPasswordTemplate,;
				lnRevert,;
				lcWritePasswordDocument,;
				lcWritePasswordTemplate,;
				lcConnection,;
				lcSQLStatement,;
				lcSQLStatement1,;
                                     wdMergeSubTypeWord2000)
HTH

>I am having trouble attaching a datasource to Word XP for Mailmerge.
>The code below works fine for VFP 6 & 7 and Word 97 & 2000.
>It just will not work with Word XP.
>
>The Macro Recorder creates an OCD (Office Connection Document) and uses this instead of a VFP Table.
>
>I have reviewed all books & UT. I can usually find something on UT to solve my problem.
>Is anyone else having problems w/ MailMerge in Word XP???
>
>
>
>
>
>Clear
>On Error
>Set Exclusive off
>
>Close Databases all
>Create Database Addbs(Sys(2023))+"Test"
>Create Table Addbs(Sys(2023))+"MailMerge" (Field_1 C(15))
>Insert Into MailMerge (Field_1) Values ("2001-12345")
>Use In Select("MailMerge")
>
>oWord			= Getobject("","Word.Application" )
>lcWordVersion	= oWord.Version()
>MessageBox([Word Version ]+lcWordVersion)
>tcMailMergeFile	= Addbs(Sys(2023))+"MailMerge.dbf"
>tcMailMergeFile	= "C:\MailMerge.dbf"
>wdOpenFormatAuto = 0
>wdDoNotSaveChanges	= 0
>
>oDocument = oWord.Documents.Add(,,0)
>lcDocumentName	= oDocument.Name
>oWord.Visible = .T.
>
>** Office 97 & 2000
>**	Results from Word 2000 Macro Recorder
>*!*	    ActiveDocument.MailMerge.OpenDataSource Name:= _
>*!*	        "C:\MailMerge.DBF" _
>*!*	        , ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
>*!*	        AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
>*!*	        WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
>*!*	        Format:=wdOpenFormatAuto, Connection:= _
>*!*	        "DSN=FoxPro Files - Word;UID=;PWD=;SourceDB=C:\;SourceType=DBF;Exclusive=No;BackgroundFetch=No;Collate=MACHINE;Null=Yes;Deleted=Yes;" _
>*!*	        , SQLStatement:="SELECT * FROM MailMerge.DBF", SQLStatement1:=""
>
>	lcRootPath			= JustPath(tcMailMergeFile) + ";"
>	lcDataFile			= JustFName(tcMailMergeFile)
>	lcName				= tcMailMergeFile
>	lnConfirmConversions	        = .F.
>	lnwdOpenFormatAuto		= .F.
>	lnReadOnly			= .F.
>	lnLinkToSource			= .T.
>	lnAddToRecentFiles		= .F.
>	lcPasswordDocument		= ""
>	lcPasswordTemplate		= ""
>	lnRevert			= .F.
>	lcWritePasswordDocument	        = ""
>	lcWritePasswordTemplate	        = ""
>	lcConnection			= "DSN=FoxPro Files - Word;UID=;PWD=;";
>				+ "SourceDB=" + lcRootPath ;
>				+ "SourceType=DBF;Exclusive=No;";
>				+ "BackgroundFetch=Yes;Collate=MACHINE;";
>				+ "Null=Yes;Deleted=Yes;"
>
>	lcSQLStatement			= "SELECT * FROM " + lcDataFile
>	lcSQLStatement1			= ""
>
>
>
>	lcOnError = ON("Error")
>	llDataSourceCreated = .T.
>	On Error llDataSourceCreated = .F.
>    oWord.ActiveDocument.MailMerge.OpenDataSource(;
>				lcName,;
>				lnwdOpenFormatAuto,;
>				lnConfirmConversions,;
>				lnReadOnly,;
>				lnLinkToSource,;
>				lnAddToRecentFiles,;
>				lcPasswordDocument,;
>				lcPasswordTemplate,;
>				lnRevert,;
>				lcWritePasswordDocument,;
>				lcWritePasswordTemplate,;
>				lcConnection,;
>				lcSQLStatement,;
>				lcSQLStatement1 )
>	On Error &lcOnError
>	
>If llDataSourceCreated = .F.
>	MessageBox("MailMerge - OpenDataSource Failed")
>	oWord.Quit(wdDoNotSaveChanges)
>Else
>	oWord.Visible = .T.
>	Wait Window "OpenDataSource - Finished"
>EndIf
>
>
>
Caroline
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform