In an effort to tackle some of the issues am I faced with in automating a Word 97 document from VFP 5, I have came up with this code, which is in the Click() event of a command button on the user form. It opens a word doc, fills it with values from a table, then saves it off with a new file name and closes the word document and the instance of word. Does anybody see any 'gotchas" or anything else I may be missing? It is running properly and I just want to be sure I'm not opening up a can of worms by neglecting anything. BTW, I apologize for the lengthy post.
Thanks for any help,
Patric Ainsworth
PS (John, I appreciate the head start earlier... It was very helpful)
** CODE BEGINS HERE **
** Set up Constants
#DEFINE CRLF CHR(13)+CHR(10)
#DEFINE PUNCT ","
** Create an Instance of Word
oWord=CREATE('Word.Application')
** Open a Blank Document named 'NewDoc' (This insures I am using a ** blank document)
oWord.Documents.Open('C:\DOCS\NewDoc.Doc')
** Open the department reference table
SELECT DeptRef
** Determine the number of records
nNumRecs=RECCOUNT()
** Reset pointer to top of file
GO TOP
** Scan through each record. If it is the last record in the table,
** end with a hard CR, otherwise place a comma after each record
SCAN
IF RECNO() <> nNumRecs
oWord.Selection.insertafter(alltrim(desc)+PUNCT)
ELSE
oWord.Selection.insertafter(alltrim(desc)+CRLF)
ENDIF
ENDSCAN
** Save the document to 'NewDoc2'. If NewDoc2 exists, it is
** overwritten. NOTE: The path MUST be specified or the doc will
** be saved in C:\MYDOCUMENTS directory
oWord.Documents('C:\DOCS\NewDoc.Doc').SaveAs('C:\DOCS\NewDoc2.Doc')
** Close the instance of Word
oWord.Quit
** Close and release the form
THISFORM.RELEASE
** END CODE **