Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Changing from ODBC to OLEBD for Word automation
Message
From
04/10/2006 11:32:00
Loraine Spaeth
Housing Data Systems, Inc.
Wisconsin, United States
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
Changing from ODBC to OLEBD for Word automation
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01159380
Message ID:
01159380
Views:
80
Hi. I hope someone (Cindy?) can help me see what I am doing wrong. I have searched UT and elsewhere and still can't seem to get my mailmerge to work using vfpoledb. We have been using ODBC with DSN=Visual FoxPro Tables for years and have managed to keep it working despite Microsofts frequent version changes. Now I am trying to gear up for Vista and Office12 by switching to oledb, but am struggling. In my simplified code below, the ODBC connection works fine, but when I run the OLEDB branch, I get the error: "OLE IDispatch exception code 0 from Microsoft Word: Word was unable to open the data source..."

I am hesitant to go to a txt file because we also merge memo fields at times.

LPARAMETERS tcTypeofConn

LOCAL loWordApp, loMailMerge

* START WORD
loWordApp = NEWOBJECT("word.application")
loWordApp.Visible = .T.

* Open the Word document
* Parms: docname, confirm conversions (true-default),
* Read-only (false=0 true=1), AddToRecentFiles (false=0)
loWordApp.documents.Open("C:\test oledb.doc",,1,0)

* Create mailmerge object ref.
loMailMerge = loWordApp.activedocument.mailmerge

* SETUP THE DATA CONNECTION AND ATTACH THE DATASOURCE
LOCAL lcSql, lcConnection

lcSql = "SELECT * FROM test.dbf"

* Put it all together and Attach the data source to the open document
* For Wd2000 and more recent
IF tcTypeofConn = 'ODBC'
lcConnection = "DSN=Visual FoxPro Tables;SourceDB= C:\" ;
+ ";Source Type=DBF;Exclusive=No;BackgroundFetch=Yes"
loMailMerge.opendatasource("c:\test.dbf",0,0,0,0,0,"","",0,"","",lcConnection,lcSQL,"",0,8)
ELSE
* OLEDB
lcConnection = "Provider=vfpoledb.1;Data Source=C:\;Mode=ReadWrite"
loMailMerge.opendatasource("c:\test.dbf",0,0,0,0,0,"","",0,"","",lcConnection,lcSQL,"",0,8)
ENDIF

* Create the merged letter
loMailMerge.Destination = 0 && 0=SendToNewDocument 'Form Letter1'
loMailMerge.Execute

Thanks for whatever help you can offer!
Loraine
Reply
Map
View

Click here to load this message in the networking platform