General information
Category:
COM/DCOM and OLE Automation
Title:
Changing from ODBC to OLEBD for Word automation
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
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