Home |
Search |
Today's Posts |
#1
|
|||
|
|||
Using VBA to merge complex data
I have a Word XP document with merge codes (converted from WP). The data
source is several tables from my database. Rather than construct a complex query to get all of the data into a single table to use as my merge data source, I want to use VBA to populate the document. How can I identify the Mergefields in code to achieve this? |
#2
|
|||
|
|||
I would suggest that creating a query to combine the data from the tables
would be far simpler than what you are proposing. -- Please respond to the Newsgroup for the benefit of others who may be interested. Questions sent directly to me will only be answered on a paid consulting basis. Hope this helps, Doug Robbins - Word MVP "JBob" x wrote in message ... I have a Word XP document with merge codes (converted from WP). The data source is several tables from my database. Rather than construct a complex query to get all of the data into a single table to use as my merge data source, I want to use VBA to populate the document. How can I identify the Mergefields in code to achieve this? |
#3
|
|||
|
|||
I am able to use the following construct to achieve what I need (that is,
using VBA to populate merge fields): ' '-- replace all occurrences of Analyst (mergefield in main document) ' sSQL = "select FirstName, LastName, FullTitle from Employees where Initials='" & sAnalystInitials & "'" rsADO.Open sSQL, gsConnect, adOpenForwardOnly, adLockReadOnly, adCmdText sAnalyst = rsADO!Firstname & " " & rsADO!lastname & ", " & rsADO!FullTitle rsADO.Close Dim fieldLoop As Field For Each fieldLoop In ActiveDocument.Fields If InStr(1, fieldLoop.Code.Text, "Analyst", 1) Then fieldLoop.Select Selection.TypeText sAnalyst End If Next fieldLoop Some Questions: 1. Is there a better way? 2. Am I in the right newsgroup for this problem? "Doug Robbins" wrote in message ... I would suggest that creating a query to combine the data from the tables would be far simpler than what you are proposing. -- Please respond to the Newsgroup for the benefit of others who may be interested. Questions sent directly to me will only be answered on a paid consulting basis. Hope this helps, Doug Robbins - Word MVP "JBob" x wrote in message ... I have a Word XP document with merge codes (converted from WP). The data source is several tables from my database. Rather than construct a complex query to get all of the data into a single table to use as my merge data source, I want to use VBA to populate the document. How can I identify the Mergefields in code to achieve this? |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Specific Email Merge w/ Specific Attachements | Mailmerge | |||
Mail merge data source problem | Mailmerge | |||
stripping commas from merge data | Mailmerge | |||
Mail merge error occurs when filtering Excel data source | Mailmerge | |||
Merge Data Source path | Mailmerge |