none
merge codes sql database data RRS feed

  • Question

  • Hi,

    I have a database of customers and I have their address information, I have 5 letters that I have to send these clients but I don't have to do this all at once so a mail merge is not what I need. When a customer needs to be sent a certain letter I want to select the customer and then when I open up a word document I want to extract the customers address information and populate the letter.

    I think the following is needed;

    Merge codes, a sql connection that runs a query and then fills in a dataset and then the dataset populates the merge codes.

    Not sure how to accomplish this.. anyone got ideas on what the best way to do this.. or tutorials I could look at.. or some code..?

    I am wanting to do this using C#, sql server and using word 2010 and word 2007. Thanks

    Just see this link using content controls and the populating using c#

    http://msdn.microsoft.com/en-us/library/bb386290

    Is this a possibility?

    • Edited by Taus Wednesday, June 13, 2012 10:47 PM
    Wednesday, June 13, 2012 9:43 PM

Answers

  • That's really up to you. A mailmerge can execute the query, thus eliminating the extra step that creating a separate dataset would entail.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by Taus Thursday, June 14, 2012 12:46 PM
    Thursday, June 14, 2012 11:28 AM

All replies

  • You could still use a mailmerge, with either a filter or an interactive SKIPIF field to limit the output to a single record. The interactive SKIPIF field might be coded as:
    {SKIPIF{MERGEFIELD MyField}<>{FILLIN "Record to output" \o}}
    where 'MyField' is the name of the field you want to filter on.

    Note: The field brace pairs (ie '{ }') for the above example are created via Ctrl-F9 - you can't simply type them or copy & paste them from this message.


    Cheers
    Paul Edstein
    [MS MVP - Word]


    • Edited by macropodMVP Thursday, June 14, 2012 9:06 AM
    Thursday, June 14, 2012 9:05 AM
  • Thanks for the reply should I retrieve the sql data and place this in a dataset and then do the mail merge for the letter?

    Is this the best way? Or is there another way of achieving this?

    Thursday, June 14, 2012 10:59 AM
  • That's really up to you. A mailmerge can execute the query, thus eliminating the extra step that creating a separate dataset would entail.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by Taus Thursday, June 14, 2012 12:46 PM
    Thursday, June 14, 2012 11:28 AM