Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word 97 Problem in VFP 5
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00123352
Message ID:
00123353
Views:
26
Patric,

Here's your code trimmed down a little. This should also run faster.

** CODE BEGINS HERE **

** Set up Constants
#DEFINE CRLF CHR(13)+CHR(10)
#DEFINE PUNCT ","
* Declare the variable local so it doesn;t interfere with any other thing that
* may use oWord for a variable
LOCAL oWord, lnFirstRec
** 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()
* Don't beed the above RECCOUNT(), see the scan loop to find out why
** Reset pointer to top of file
LOCATE && this is faster than GO TOP
lnFirstRec = RECNO()

** 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
oWord.Selection.insertafter(IIF(RECNO()<>lnFirstRec,PUNCT,"")+alltrim(desc))
ENDSCAN
oWord.Selection.insertafter(CRLF)

** 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 **

The only thing I think may have given you trouble before is deleted records. They could cause reccount to not be equal to the last record number you process.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform