Sorry it has taken a while to get back to you on this.
I do not know what is going wrong where you are, but here the following
things worked, using Word 2003 and
a. the Visual FoxPro ODBC driver called "Microsoft Visual FoxPro Driver"
version 6.01.8629.01 (it also has a Portuguese name, "Driver para o
Microsoft Visual FoxPro")
b. the visual FoxPro OLEDB Provider version
Let's assume you have a folder called c:\fp containing a .dbc called db.dbc
and some .dbf files associated with the .dbc, including one called t.dbf
Then you should be able to connect in the following ways (at least):
Using ODBC to connect
-----------------------------------
Create an ODBC User or System DSN called fox.It doesn't matter whether you
set it up for a DBC or DBFs
For a DBC, use the following OpenDataSource call (sorry, you will need to
fix the line wrapping):
ActiveDocument.MailMerge.OpenDataSource _
Name:="", _
Connection:="DSN=fox;UID=;PWD=;SourceDB=C:\fp;SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;Null=Yes;Deleted=Yes;",
_
SQLStatement:="SELECT * FROM `t`", _
SubType:=wdMergeSubTypeWord2000
For a DBF, use the following OpenDataSource call:
ActiveDocument.MailMerge.OpenDataSource _
Name:="", _
Connection:="DSN=fox;UID=;PWD=;SourceDB=C:\fp\db.dbc;SourceType=DBC;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;Null=Yes;Deleted=Yes;",
_
SQLStatement:="SELECT * FROM `t`", _
SubType:=wdMergeSubTypeWord2000
Using OLEDB to connect
--------------------------
I am fairly sure that you cannot specify the .dbc or .dbf in the Name
parameter. I think you have to have a .udl or .odc file. These are just
plain text files that are supposed to provide connection details. However,
as far as I know either type of file can be an empty text file that you can
create in Notepad. Let's suppose you have such a file called c:\fp\fox.udl
Then try:
ActiveDocument.MailMerge.OpenDataSource _
Name:="c:\fp\fox.udl", _
Connection:="Provider=VFPOLEDB.1;Data Source=c:\fp\db.dbc;Mode=Share
Deny None;User ID="""";Password="""";", _
SQLStatement:="SELECT * FROM `t`"
or:
ActiveDocument.MailMerge.OpenDataSource _
Name:="c:\fp\fox.udl", _
Connection:="Provider=VFPOLEDB.1;Data Source=c:\fp;Mode=Share Deny
None;User ID="""";Password="""";", _
SQLStatement:="SELECT * FROM `t`"
If you want the user to be able to select the dbf, given a folder or dbc, I
suspect it is possible using a .odc, but ask again. (I will not be back for
a few days).
Peter Jamieson
To connect to a dbf, try