Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mailmerge from VFP 1

Status
Not open for further replies.

mike2p

Programmer
Jan 21, 2001
6
CY
Hi to all,
We are trying to mailmerge the current record to a word document.
Does anyone have the code snippet for this?
Thanks in advance
Regards
Mike
 
mike2sp

The following does not really use the mail-merge feature of Word, but instead uses field insertion:
Code:
LPARAMETERS cSignee,cTitle,ldDate,nCheck
LOCAL cWordTemplate,loTemplate,nCount,x,loDocument
x = 0
cWordTemplate = GETFILE("dot","Get letter template","Use")
IF !EMPTY(cWordTemplate)
    oWord = CREATEOBJECT("word.application")
    this.oWord = .t.
    oWord.Documents.OPEN(cWordTemplate)
    loTemplate=oWord.SELECTION
    loTemplate.WholeStory
    loTemplate.COPY
    loDocument=oWord.Documents.ADD()
    SELECT EMP2
    GO TOP
    COUNT TO nCount
    GO TOP
    DO WHILE !EOF()
        x = x + 1
        WITH oWord
            loSelection = oWord.SELECTION
            loSelection.PageSetup.TopMargin = 30
            loSelection.InlineShapes.AddPicture("c:\word letter\graphics\slpcanada2.bmp")
            loSelection.PageSetup.RightMargin=50
            loSelection.PageSetup.LeftMargin=50
            loSelection.typeparagraph
            loSelection.typeparagraph
            loSelection.typeparagraph
            loSelection.PageSetup.BottomMargin = 30
            loSelection.FONT.SIZE = 12
            loSelection.FONT.NAME = "times"
            loSelection.TypeText(ALLTRIM(ldDate))
            loSelection.typeparagraph
            loSelection.typeparagraph
            loSelection.Font.Bold = .t.
            loSelection.TypeText(ALLTRIM(PROPER(EMP2.empfname))+" "+ALLTRIM(PROPER(EMP2.emplName)))
            loSelection.typeparagraph
            loSelection.FONT.SIZE = 10
            loSelection.FONT.NAME = "times"
            loSelection.Font.Bold = .f.
            loSelection.TypeText(ALLTRIM(EMP2.address))
            loSelection.typeparagraph
            loSelection.TypeText(ALLTRIM(EMP2.city)+", "+ALLTRIM(EMP2.province))
            loSelection.typeparagraph
            loSelection.TypeText(SUBSTR(EMP2.postal,1,3)+"-"+SUBSTR(EMP2.postal,4,3))
            loSelection.typeparagraph
            loSelection.typeparagraph
            loSelection.FONT.SIZE = 12
            loSelection.FONT.NAME = "times"
            IF nCheck = .t.
                loSelection.TypeText(IIF(!EMP2.madame,"Monsieur","Madame")+" "+ALLTRIM(PROPER(EMP2.emplName)))
            ENDIF
            loSelection.typeparagraph
            loSelection.typeparagraph
            loSelection.Paste
            loSelection.typeparagraph
            loSelection.typeparagraph
            loSelection.typeparagraph
            loSelection.typeparagraph
            IF x < nCount
                loSelection.insertbreak()
            ENDIF
        ENDWITH
        SELECT EMP2
        SKIP
    ENDDO
    nAnswer = MESSAGEBOX(&quot;Do you want to print to document(s)?&quot;,36,&quot;Letter&quot;)
    IF nAnswer = 6
        oWord.printout()
         loDocument.SAVEAS(&quot;c:\word letter\documents\letter.doc&quot;)
        DELETE FILE c:\word letter\documents\letter.doc
    ENDIF
ELSE
    MESSAGEBOX(&quot;You have not selected a template, please try again.&quot;)
ENDIF



Mike Gagnon
comp14.gif
 
darrellblackhawk

Very nice mgagnon. How fast is it?

You'll notice, it does actually only one document for all &quot;employees&quot; so in fact all you need to print is one one document. So yes, pretty fast.


Mike Gagnon
comp14.gif
 
Thanks a lot to all
You have been very helpfull
Regards
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top