Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
HELP - Datasource will not attach to WORD XP for Mail Merge
Message
From
03/10/2002 14:04:07
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
HELP - Datasource will not attach to WORD XP for Mail Merge
Miscellaneous
Thread ID:
00707443
Message ID:
00707443
Views:
89
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
Map
View

Click here to load this message in the networking platform