Reply
 
Thread Tools Display Modes
  #1   Report Post  
JBob
 
Posts: n/a
Default 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   Report Post  
Doug Robbins
 
Posts: n/a
Default

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   Report Post  
JBob
 
Posts: n/a
Default

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

Posting Rules

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Specific Email Merge w/ Specific Attachements Mark B Mailmerge 9 February 21st 05 05:10 AM
Mail merge data source problem campwes Mailmerge 1 January 25th 05 07:16 PM
stripping commas from merge data Patrick Heilman Mailmerge 0 December 30th 04 04:09 AM
Mail merge error occurs when filtering Excel data source Dave Mailmerge 1 December 2nd 04 10:46 PM
Merge Data Source path Peter Jamieson Mailmerge 0 November 25th 04 07:15 PM


All times are GMT +1. The time now is 10:53 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"