Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How can I mail merge a .csv file, matching fields, into a Word doc | Microsoft Word Help | |||
Empty Mail Merge Fields | Microsoft Word Help | |||
Mail Merge - DataPerfect database to Word | Mailmerge | |||
Problem with mail merge and works database | Mailmerge | |||
Word mail merge doesn't pick up the addresses in Access database. | Tables |