*!* First a word.doc is created and saved. Also a bookmark (plsinserthere) is added for VFP marking data placement. *!* (Bookmarks such as header,footer etc could make an existing word.doc behave like a report). *!* Then opened as an existing word.doc and first 10 recs from employee table are inserted at bookmark. *!* File is printed and exited (no save). *!* Some lines are commented to show word.basic or VBA counterparts. #define NL chr(13) PUBLIC oWordDocument *** set the LOCALEID to English nlLocaleId=sys(3004) && Save local id =sys(3006,1033) && We will be sending instructions in English use home()+"samples\data\employee" && test table wait window nowait "Creating Word Document..." oWordDocument=createobject("word.application") && Create word object with oWordDocument.wordbasic && Word.basic and VBAword commands are used * .appshow && Show word app .filenewdefault && New file, default template .insert("This is our existing word document. Data from VFP will be inserted starting after repeating our comments."+NL) .insert("First a word.doc is created and saved. Also a bookmark (plsinserthere) is added for VFP marking data placement.") .insert("(Bookmarks such as header,footer etc could make an existing word.doc behave like a report).") .insert("Then opened as an existing word.doc and first 10 recs from employee table are inserted at bookmark.") .insert("File is printed and exited (no save).") .insert("Some lines are commented to show word.basic or VBA counterparts."+NL+"*****************"+NL) .editbookmark("PlsInsertHere",,1) && Added our bookmark * oWordDocument.activedocument.bookmarks.add(cBookmark) - VB syntax && .goto for go .delete for delete etc .insert("*********************"+NL+"VFP data ends here. Any other comments....") .filesaveas(curdir()+"oursample.doc") && Save so this will be our existing doc. .fileclose(1) && Close file saving .fileopen(curdir()+"oursample.doc") && Open "existing" doc. .editbookmark("PlsInsertHere",,,,1) && Go to our bookmark scan while recno() <= 10 .formatfont(12,,5) && 12 points, magenta - just to identify VFP data .insert(ltrim(str(recno()))+"-"+trim(employee.last_name)+","+employee.first_name+NL) && Insert employee name .insert(employee.notes+NL+NL) && Insert employee notes endscan wait window nowait "Printing now.." oWordDocument.activedocument.printout(0) && Print REPORT,no background - .fileprint(0) wordbasic way wait window "Word finished printing." nowait .fileexit(2) && Exit no save, so old doc intact endwith =sys(3006,val(nlLocaleId)) release oWordDocument * Below is mailmerge way *!* cDSN = "DSN=Visual FoxPro Tables;UID=;PWD=;" *!* cSourceDb = "SourceDB=C:\Program Files\vfp50\SAMPLES\DATA\Testdata.dbc" *!* cSourceType = ";SourceType=DBC;" *!* cOther = "Exclusive=No;BackgroundFetch=No;Collate=Machine;" *!* cSQLStatement = "SELECT * FROM customer" *!* .InsertDatabase(35,511,1, ; *!* cDSN+cSourceDb+cSourceType+cOther, ; *!* cSQLStatement,,,,,,,1) && 35,511 table autoformat values 1 link to source *!* .filesaveas("xxmmergedoc",0) && Save as a word doc for mailmerge *!* .fileclose(1) && Close saving *!* .filenewdefault && New file, default template *!* .MailMergeOpenDataSource("xxmmergedoc.doc") && Set saved file as data source for mailmerge (Directly a table could be set via ODBC) *!* .MailMergeEditMainDocument && Activate the main document *!* .Insert("Dear ") && Start writing *!* .InsertMergeField("Contact") && Insert a merge field *!* .Insert(",") *!* ..... *!* .mailmergetoprinter **** Set the LocaleId to the previous valueHope it helps