General information
Category:
COM/DCOM and OLE Automation
Title:
HELP - Datasource will not attach to WORD XP for Mail Merge
I have been working on this problem for a while and still cannot resolve it.
I have Referenced "Micosoft Office Automation with VFP" by Tamar Granor, and Universal Thread for Mail Merge. So far all the reference material I have found has not helped.
I have code that works with VFP 6 & 7 to Mailmerge using Word 2000 (oWord.Version = 9)
When I try the code against WORD XP (oWord.Version = 10) the datasource does not get connected. I can attach the datasource manually and use Macro Recorder to capture the statement Word XP uses. When I go thur the process Word ends up creating an .odc (Office Database Connection) file.
Any help would be appreciated.
Lee Raulerson
******************
Code from Word XP
******************
ActiveDocument.MailMerge.OpenDataSource
Name:= "C:\...\My Data Sources\xp mailmerge.odc",
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True,
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="",
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False,
Format:=wdOpenFormatAuto,
Connection:= "Provider=VFPOLEDB.1;Data Source=C:\JCS.DBC;
Mode=Share Deny None;Extended Properties="""";
User ID="""";Password="""";Mask Password=False;
Cache Authentication=False;Encrypt Password=False;Collating S",
SQLStatement:="SELECT * FROM `mailmerge`",
QLStatement1:="", SubType:= wdMergeSubTypeOther
************************************
Code that works with VFP & Word 2000
************************************
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
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only