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
...

Open in new window

ASKER CERTIFIED SOLUTION
GrahamSkan
Retired

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Top Expert 2012

The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 2 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 2 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004