>I have a foxpro 7.0 application that used the following code to merge a VFP Table (with long field names) with a Word Document. It doesn't work with Word XP, and errors out with the message: "Word was unable to open the data source." This code works fine with Word 2000. I have installed the latested FoxPro ODBC drivers (dated 12/99) I read the article on this category and downloaded the "latest" which had the same date...with no change (it still doesn't work).
>
>oWord = CreateObject("word.application")
>m.oDoc = oWord.documents.Open("my_merge.doc")
>m.cMergeFileName = "c:\test\test_merge.dbf"
>
>* This is a dbf with long field names and a dbc with the same name in the same folder. The DSN points to this file. Although it doesn't matter because of the SourceDB is and overrides the one specified in the ODBC administrator.
>
>m.cDataSource = "DSN=Word - Merge;UID=;PWD=;"+;
> "SourceDB="+JUSTPATH(m.cMergeFileName) + ;
> ";SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;"+;
> "Collate=MACHINE;Null=Yes;Deleted=Yes;"
>
>oDoc.MailMerge.OpenDataSource( ;
> m.cMergeFileName, 0,0,0,0,0,"","",0,"","", ;
> m.cDataSource, "SELECT * FROM "+JUSTFNAME(m.cMergeFileName),"")
>
>oWord.Visible = .T.
>oWord.Activate()
>
>I've heard there is a different approach in VFP 8.0 with the Foundation Class. I haven't gone to 8.0 yet. And have too many clients on 7.0 to go around updating their runtime files, etc...unless required.
>
>Does anyone know how to fix this for Word XP? This really can drive you crazy because you would hope that code would be upwardly compatible...ha ha.
>
>Thanks.
>
>Bob Bartel
>marketware
Bob,
I don't have Word XP to test. Something else draw my attention. You say long field names but point to a free table, typo ?
Would this work with Word XP :
Create Database WordMM
Create Table WordMM1 (verylongfieldname1 c(10), verylongfieldname2 i)
For ix=1 To 10
Insert Into WordMM1 Values (Sys(2015), ix)
Endfor
Close All
#Define MYDBC Fullpath("WordMM.dbc")
#Define wdSendToNewDocument 0
cSQLStatement1 = "SELECT * FROM wordMM1"
cSQLStatement2 = ""
oWordDocument=Createobject("word.application")
With oWordDocument
.Documents.Add
With .ActiveDocument.MailMerge
.OpenDataSource(,,,.T.,,,,,,,, ;
"DSN=Visual FoxPro Database;SourceDB="+MYDBC+;
";SourceType=DBC;Exclusive=No;",;
cSQLStatement1, cSQLStatement2)
.EditMainDocument
.Application.Selection.TypeText("Company :")
.Fields.Add(.Application.Selection.Range,'VeryLongFieldName1')
.Application.Selection.TypeText(Chr(13)+"Contact :")
.Fields.Add(.Application.Selection.Range,'VeryLongFieldName2')
.Application.Selection.TypeText(Chr(13)+"Blah blah ...."+Chr(13))
Endwith
.Visible = .T.
.Activate
Endwith
Cetin