General information
Category:
COM/DCOM and OLE Automation
Title:
Word automation and VFP.
Hello,
I am trying to create a mail merge document and add one text and one field from a file called merge.dbf. I run the following code in VFP6 (moving to 8)
and get a dialog box asking to "Select Data Source". Here is the code:
#Define MYDBC "c:\proj2000\data\merge.dbf"
cSQLStatement1 = "SELECT * FROM Merge"
cSQLStatement2 = ""
oWordDocument=createobject("word.application") && Create word object
With oWordDocument
.Documents.Add && Use a predefined template if u wish
With .ActiveDocument.MailMerge
.OpenDataSource(,,,.T.,,,,,,,, ;
"DSN=Visual FoxPro Database;SourceDB="+MYDBC+;
";SourceType=DBF;Exclusive=No;",;
cSQLStatement1, cSQLStatement2) && Open data source - Link to source
.EditMainDocument && Activate the main document
.Application.Selection.TypeText("First Name :")
.Fields.Add(.Application.Selection.Range,'firstname')
.Application.Selection.TypeText(CHR(13)+"Blah blah ...."+Chr(13))
ENDWITH
.Visible = .t.
.Activate
EndWith
Any ideas what I am doing wrong? I need something VERY simple.
Thanks,
-Greg
Next
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