Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
 
Posts: n/a
Default Update fields of mail merge based on lookup to database

I am trying to use the mail merge features of Word to create a template
or form that will create one document based on a lookup to an external
database. I would ask the user to fill in the name of the server they
are interested in and populate the rest of the mail merge fields with
the pertinate information associated with that server name. I have been
able to set up my document to get the necessary data but cannot figure
out how to create a fillin field that will actually go and look the
data up.

Can any one point me in the right direction?

  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP
 
Posts: n/a
Default Update fields of mail merge based on lookup to database

You use the terms database and server as if they are perhaps the same thing,
or do you really mean that you want to create a single document that
contains the data from a single record in one table in a database.

If that's really what you are doing, then I would use a userform containing
a listbox that was populated with the data from the database and then the
user could select an item from the listbox and when they then clicked on a
button on the userform, the data from the fields in that record would be
inserted into the document.

See the article "How to create a Userform" at:

http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm

The following is the code that you would use to populate a listbox with data
from a table in an access database:

Private Sub UserForm_Initialize()

Dim db As DAO.Database

Dim rs As DAO.Recordset

Dim NoOfRecords As Long

' Open the database

Set db = OpenDatabase("D:\Access\ResidencesXP.mdb")

' Retrieve the recordset

Set rs = db.OpenRecordset("SELECT * FROM Owners")

' Determine the number of retrieved records

With rs

.MoveLast

NoOfRecords = .RecordCount

.MoveFirst

End With

' Set the number of Columns = number of Fields in recordset

ListBox1.ColumnCount = rs.Fields.Count

' Load the ListBox with the retrieved records

ListBox1.Column = rs.GetRows(NoOfRecords)

' Cleanup

rs.Close

db.Close

Set rs = Nothing

Set db = Nothing

End Sub



--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

wrote in message
oups.com...
I am trying to use the mail merge features of Word to create a template
or form that will create one document based on a lookup to an external
database. I would ask the user to fill in the name of the server they
are interested in and populate the rest of the mail merge fields with
the pertinate information associated with that server name. I have been
able to set up my document to get the necessary data but cannot figure
out how to create a fillin field that will actually go and look the
data up.

Can any one point me in the right direction?



  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
 
Posts: n/a
Default Update fields of mail merge based on lookup to database

When I mentioned database and server, it was a database containing
information about servers we maintain. The database is a mySql database
with multiple tables and my query contains the joins to pull the info
into the form. I guess a list box will work. I will just have to modify
your VB code to use a ODBC connection.

Thanks

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I mail merge a .csv file, matching fields, into a Word doc Fluffy from Wisconsin Microsoft Word Help 3 May 19th 05 01:38 PM
Empty Mail Merge Fields Meggan Microsoft Word Help 1 January 13th 05 05:22 AM
Mail Merge - DataPerfect database to Word DustyD Mailmerge 1 January 8th 05 09:49 AM
Problem with mail merge and works database techman Mailmerge 2 December 1st 04 04:47 PM
Word mail merge doesn't pick up the addresses in Access database. Julie Tables 1 November 24th 04 01:26 AM


All times are GMT +1. The time now is 06:12 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"