>In both DataFlex and FP 2.X I have used a form
>letter system where the user creates an Ascii file
>and embeds references to program variables in angle
>brackets:
>
>******************************************************
>{(8U}{(s1p20v0s3b4148T} {&a12L}
>
> Rental Services
>{(8U}{(s1p12v0s0b4101T}
>
>< N.NAME >
>< N.ADDR1 >
>< N.ADDR2 >
>< N.CITY >, < N.STATE > < N.ZIP >
>< N.NOTE >
>
>< LETTER_DATE >
>
>Thank you for making reservations with us...
>
>*****************************************************
>(I added the blanks after the carets to avoid
>confusing the HTML.)
>
>There was also embedded PCL code as you can see.
>
>This approach worked very well because the user
>could create many new form letters without ever
>talking to me.
>
>I have not been able to get the embedded PCL
>approach to work with Windows 95 so I am considering
>abandoning this approach and using WORD, possible
>with OLE.
>
>Does anyone know of a way to achieve the same end
>result: new form letters can be created without changing
>the VFP program?
>
>Peter Robinson
I wrote something almost exactly like this for a client a few months ago. Basically, the program opens a word document specified by the user, and searches it for any bookmarks with the same name as a set of fields I made available. IF the bookmarks are found, they are replaced with the current values of those fields.
Here is some simplified code:
oWord.fileopen(filename)
bmcount = oWord.countbookmarks()
IF bmcount > 0
FOR i = 1 TO bmcount
cbookmarkname = oWord.bookmarkname(i)
IF TYPE((cbookmarkname)) <> "U" then
DO CASE
CASE TYPE((cbookmarkname)) = "C" OR TYPE((cbookmarkname)) = "M"
fieldvalue = ALLTRIM(EVAL(cbookmarkname))
CASE TYPE((cbookmarkname)) = "N"
fieldvalue = ALLTRIM(STR(EVAL(cbookmarkname)))
CASE TYPE((cbookmarkname)) = "D"
fieldvalue = DTOC(EVAL(cbookmarkname))
ENDCASE
oWord.editbookmark(cbookmarkname,,,,1)
oWord.INSERT(fieldvalue)
ENDIF
ENDFOR
ELSE
lanswer=MESSAGEBOX(INVALID_DOC_LOC,0,APP_NAME_LOC)
IF lanswer = 6
ENDIF
ENDIF
This is assuming you have already opened and gotten a reference to Word using
oWord = GETOBJECT('','Word.Basic')
I hope this is enough to get you started, and let me know if you have any further questions.
Erik Moore
Clientelligence