New to Word integration using DDE

We currently are using word integration that involves a foxpro table where each field represents a mergeable item.  The data from the foxpro table is pumped into an excel spread sheet and then into Word.  I want to eliminate excel as well as get around the limit of being only able to have 255 merge fields.  To this end I want to have one foxpro table that contains two fields , the first field will hold all the merge field names, and the second will hold the value to be used to substitued when a word document is pulled up containing the merge fields.  Has anyone tried the record based approach rather or can you only use table fields to represent merge fields and a single record which represents the data to substitute the field merge name with.

Hope this makes sense.

Stuart  



Answer this question

New to Word integration using DDE

  • Steve McCormick

    Hi Marcia,

    I appreciate your reply... we are using DDE as it is a foxpro2.6 app. To be clearer each record in the table has one field that contains the merge field keyname.. ie. Name or Address. The second field would be populated with the say the persons name or address and would be used as the value to substitue the merge field with.

    Can you include your website address


  • Nick Sheng

    Marcia,

    Interesting white paper -- it covers a lot of topics I want to know more about!

    But I am stumbling coming out of the gate (old hand at using Foxpro for my own data manipulation, but first time creating an app for others that can be used without me in the room).

    My paper tray on my printer doesn't handle 16,000 pages either. I would like to have my app (1) do a query by form (2) open a moverbox to allow the user to narrow down to a subset of the query [e.g. so the birthday girl doesn't get a copy of the invitation to her own surprise party], and (3) open a moverbox to select the fields for my mailmerge table.

    I have successfully prototyped (1) and (3), but I don't understand how to use the selected items side of the mover list in (2) to narrow down the table of mail merge recipients.

    Any suggestions


  • Snuckles

    What about using BookMarks I want to use a fox table that has two fields, one containing the mergefield name and the other that will hold the value that I will be using to substitue the mergield name when the document is created for printing. I could connect to the word document grab the BookMarks, seek on the table looking for the bookmark used and then substitue the value of the BookMark with the value in the second table. Any drawbacks anyone can think of when using Bookmarks I will experiment on Monday.
  • Kit Ewbank

    What about using BookMarks I want to use a fox table that has two fields, one containing the mergefield name and the other that will hold the value that I will be using to substitue the mergield name when the document is created for printing.  I could connect to the word document grab the BookMarks, seek on the table looking for the bookmark used and then substitue the value of the BookMark with the value in the second table.  Any drawbacks anyone can think of when using Bookmarks

    I actually use a similar technique in a production app that I finished in January. This BookMarks metadata has this structure

    Templatename  

    Procname  

    Source_tbl

    Source_fld  

    Bookmark    

    Rule_Text        

     

    And I use this code to process the data:

      SELECT QuoteMap

      SCAN FOR UPPER( ALLTRIM( TemplateName ) ) == UPPER( ALLTRIM( tcTemplate ) ) AND ;

               UPPER( ALLTRIM( PROCNAME ) ) == [HEADER]

        This.ReplaceBookMark( loWord )

      ENDSCAN

    This is what the ReplaceBookMArk method looks like:

    LPARAMETERS ToWord

    LOCAL lcBookMark, lcValue, loBookMark

    lcBookMark = ALLTRIM( QuoteMap.BookMark )

    *** Find out if the current value is an expression, a constant, or a field in a table and

    *** process it appropriately

    DO CASE

      CASE NOT EMPTY( QuoteMap.RuleText )

        *** Evaluate the rule text field as the value into the target table

        lcValue = TRANSFORM( EVAL( ALLTRIM( QuoteMap.RuleText ) ) )

     

      CASE NOT EMPTY( QuoteMap.Constant )

        lcValue = ALLTRIM( QuoteMap.Constant )

     

      OTHERWISE

        *** It is a field from the specified source table

        lcValue = ALLTRIM( TRANSFORM( EVAL( ALLTRIM( QuoteMap.Source_tbl ) + [.] + ALLTRIM( QuoteMap.Source_fld ) ) ) )

    ENDCASE

    *** Now replace the bookmark with the contents of the quote

    loBookMark = toWord.ActiveDocument.Bookmarks.Item( lcBookMark )    

    IF VARTYPE( loBookMark ) = Time

      loBookMark.Range.Text = lcValue

    ENDIF

     



  • Abrar

    Stuart,

    It is wise to remove excel from scenario to do a mailmerge. You don't need it. You can simply use a tab delimited text file for mailmerge.

    However what you are describing is not a mailmerge. Instead of using mergefields use document variables and set their values.


  • imdqa

    Can you include your website address

    Ooops. Sorry about that. I forgot that the URl is not in my sig line on this forum

    www.tightlinecomputers.com

    This is Visual FoxPro code, though.



  • simto

    Has anyone tried the record based approach rather or can you only use table fields to represent merge fields and a single record which represents the data to substitute the field merge name with.

    Not sure what you mean by this - but yes, you can use VFP metadata to data drive a mail merge.

    My comment is about the title of your post - DDE is ancient technology and you should not be using it - you should be using automation.

    You can download a white paper and sample code from my "Office Automation With VFP" conference session from my web site. It should help you get stated with automation.



  • Frank Forster

    Either bookmarks or document variables would do. This is from one of VFP utils:

    _SetVar("myVar1", "Some value", loWord.ActiveDocument)
    ...
    loWord.ActiveDocument.Fields.Update

    FUNCTION _SetVar
    LPARAMETERS tcVarName, tcVarValue, toDoc
    toDoc.Variables(m.tcVarName).value = iif(empty(m.tcVarValue)," ",transform(m.tcVarValue))

    This is IMHO easier than bookmark handling. However bookmarks are too perfectly valid and you could either replace a bookmark with a value or insert the value keeping the bookmark (wish it was VFP and I could give you samples, I'm too old to remember DDE*).


  • New to Word integration using DDE