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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help using macro to find record for Mail Merge in Word

Status
Not open for further replies.

jmorlock

Programmer
Apr 25, 2003
46
0
0
US
When opening a mail merge word document I would like a box to pop up asking me for a search term(ex. docket number). Once i enter the docket number and hit enter it will show the document with the corresponding docket information merged. I have been looking around for code to do this but haven't had any luck yet. If anyone else has an idea of how to do this I am open for suggestions.

Thanks in advance.

Sincerely,

Jeremy J. Morlock
IT Specialist
 
You have a database document that you want to search through by a key, right?
Does each docket number correspond to an address that you want to have it put in the word document?

Please provide a little more (and clear) information.
I'll see if I could help you.

_______________________________________

Eman_2005
Technical Communicator
 
I have a 5 page word document that has mail merge fields within. When you first open the document the mail merge fields show information from the very first record of our access database. Each our clients have a unique Docket Number as their identifier. when choosing the particular docket number the clients address and other information is merged into the word document.

To display the correct record within the word document we must
1.) open the document.
2.) choose Find Entry
3.) enter docket number
4.) Select "Look in Field"
5.) Choose Docket Number from list of possible fields.
6.) Close the Find Entry box.

What we want is to have a search box for Docket number automatically open when the word document is opened.

I don't think its going to save much time, but this is what the boss wants.

Sincerely,

Jeremy J. Morlock
IT Specialist
 
How familiar are you with VBA?
I suggest you record these steps as a macro within the DB document first, then copy this macro to the target document vba and remove it from the DB document.

In the target (to print) document, arrange like this
1- An input box to be displayed asking for the docket using a variable for the docket number (myDocket = inputBox("Please enter the docket number.").
2- Following this you define the word document object and open the DB document in the background to get this info.
3- Set the Db document object to close.
4- add the steps you copied from the DB document and edit as necessary, using the word doc object for the DB document and using the docket variable value for the search.
5- Switch the document to reveal field codes and do a search/replace.
6- Switch the field codes back to hide field codes.
7- Print the document.

Let me know if this is clear enough or if you need the precise code.
If you prefer, you can also send me the documents to emanfatih@smartistek.com
I'll send you back including the macro.
But do this really if you cannot manage it yourself :)


_______________________________________

Eman_2005
Technical Communicator
 
I figured out how to display a dialog box when the document opens. I now need to figure out how to implement code to find the record based on the entered search term.

Sincerely,

Jeremy J. Morlock
IT Specialist
 
Below code works, but is extremely slow.

With ActiveDocument.MailMerge.DataSource
' Go to first record so that all
' records are available in the search.
.ActiveRecord = wdFirstRecord
' Find the selected record.
.FindRecord FindText:=newsearchterm, _
Field:="docket_number"
End With


Sincerely,

Jeremy J. Morlock
IT Specialist
 
The code is fine. Speed depends on many factors.
Remember, word is not a database application. It's a word processor.
I don't know how many records are invloved.
Make sure the memory is not over crowded (other applications running; not enough memory or free disk-space; fragmentation; objects set and never set = nothing; etc) already when you do this. Reboot and try again.

Good luck.

_______________________________________

Eman_2005
Technical Communicator
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top