troubleshooting Question

how to perform a Word mailmerge to a particular record in SQL database using Find Recipient

Avatar of Sigh_Man
Sigh_Man asked on
.NET ProgrammingMicrosoft Word
2 Comments1 Solution534 ViewsLast Modified:
I have a VB.Net application which performs a Word document mail merge without input from the user.  An excerpt of the code is pasted below.  In my code, the merge is carried out using the desired record  by passing the relevant record number to the mail merge process using:
.FirstRecord = [RecordNumber]
.LastRecord = [RecordNumber]
...as shown in the code excerpt attached.
This method however assumes the order of the datasource (and hence the record number of the desired record) is known at the time the merge is executed.  This is the issue; I do not always know the order, and therefore I want to do the mailmerge using:
WordBasic.MailMergeFindEntry
...to find the record by harnessing Word's "Find Recipient" feature in the mailmerge toolbar, which finds a specific record in the list by searching for text.  I therefore need to know...
***How can I pass a value to the Find Recipient feature of Word?***
Please note this solution needs to work for all versions of Word from 2002 onwards, and must be fully automated - ie not require any user input during the mail merge process.
...
With oWord
     With .ActiveDocument.MailMerge
          .Destination = wdSendToNewDocument
          .SuppressBlankLines = True
          With .DataSource
               .FirstRecord = RecordNumberInMerge
               .LastRecord = RecordNumberInMerge
          End With
          .Execute(Pause:=False)
     End With
...
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros