>Hi,
>
>I am trying to automate a mailmerge using VFP6 and Word2000.
>
>Things (almost) work as planned. I am stuck with a problem of controlling WHERE insertions happen in a table. I have looked for some documentation for Tables[].Rows[] but couldn't find anything I could use.
>
>The problem is that I can get one of 2 results:
>1- the 1st row is actually inserted into the column titles making the whole merge unusable
>2- if I force an Add() at the beginning, all rows are inserted properly except I am left with the 1st row BLANK. How can I specifically delete a row ?
>
>Can anyone point me to a useful description of the few calls I need (sourcedoc, tables, rows, etc...) ?
>
>Thanks
>
>Henry
>
>The code follows:
>================================================
>* Create an instance of Word.
>This.oWord = CreateObject("Word.Application")
>* Word 2000 detaches connection if datasource not found
>If File(goapp.cMMHeader+[.doc])
> Erase (goapp.cMMHeader+[.doc])
>Endif
>* Create a document object
>This.oDocument = This.oWord.Documents.Open(goapp.cMMDocument)
>Local loSourceDoc, loRow, loTable
>Select (goapp.cMMCursor)
>With This.oDocument.MailMerge
> * Attach the data to the document
> .CreateDataSource(goapp.cMMHeader, , , goapp.cMMFieldList)
> .EditDataSource
> loSourceDoc = This.oWord.ActiveDocument
> loTable = loSourceDoc.Tables[1]
> loRow = loTable.Rows[1]
>* loRow = loTable.Rows.Add()
> * Now open the data source and put the data into the document
> Scan
> *For clarity, assume all fields are of type 'C'
> For I = 1 To Occurs([,],goapp.cMMFieldList)+1
> loRow.Cells[ I ].Range.InsertAfter(Trim( Eval(Fields( I ))))
> EndFor
> loRow = loTable.Rows.Add()
> EndScan
> loRow.Delete()
> loSourceDoc.Save()
>EndWith
Henry,
Easiest method for me to create a word table is to convert text to table (TextToTable).
If you want an approach like yours check Message #
576737For an OpenDatasource sample check Message #
635450 Here is also a sample with a free table usage :
SELECT * from customer WHERE country = 'Germany' INTO TABLE myfree
USE
lcConnStr = ;
"DSN=Visual FoxPro Tables;SourceType=DBF;SourceDB="+SYS(5)+CURDIR()+";"
cSQLStatement1 = "SELECT * FROM myfree"
cSQLStatement2 = ""
oWordDocument=createobject("word.application")
With oWordDocument
.Documents.Add
With .ActiveDocument.MailMerge
.OpenDataSource(,,,,,,,,,,, ;
lcConnStr,;
cSQLStatement1, cSQLStatement2)
.EditMainDocument
Endwith
.Application.Selection.TypeText("Dear,"+chr(13))
.ActiveDocument.MailMerge.Fields.Add(;
.Application.Selection.Range, "Contact")
.Visible = .t.
.Activate
Endwith
Cetin