You could use a Select query in access to hold the data that you want to
use.
The code that you would have in an add-in in Word would be something like
Dim myDataBase As Database
Dim myRecs As Recordset
Dim i As Long
Dim NewDoc As Document
'Open a database
Set myDataBase = OpenDatabase("C:\Documents and Settings\Doug Robbins\My
Documents\Cost Database\Cost System.mdb")
'Access the first record from a particular table
Set myRecs = myDataBase.OpenRecordset("Currencies", dbOpenForwardOnly)
'Loop through all the records in the table until the end-of-file marker is
reached
Do While Not myActiveRecord.EOF
'Create a new document from the template
Set NewDoc = Documents.Add("TemplateName")
With NewDoc
'Create and populate variables in the document with the names and
data
'from the fields in the table in the Database
For i = 1 To myRecs.Fields.Count - 1
.Variables(myRecs.Fields(i - 1).Name).Value = myRecs.Fields(i -
1)
.Range.Fields.Update
Next i
'It is assumed that the last field in the table contains the name of
the
'macro to be run.
Call myRecs.Fields(myRecs.Fields.Count - 1)
'Save the document
.SaveAs "some filename probably from a field in the database"
End With
myRecs.MoveNext
Loop
myRecs.Close
myDataBase.Close
--
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
If I had to do something like this, I would not use mailmerge as the
basis.
Rather, instead of using a mailmerge main document, I would create a
template that had {DOCVARIABLE} fields where you would have had
mergefields
in a mail merge main document and then I would use VBA to iterate through
the Access Table/Query, creating a new document from the template for each
record and creating variables in that document that would contain the data
from each field in that record. The code would also call the macro to be
executed on that document if there was one in that field of the record.
--
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
I have a generic MSAccess module that starts MSWord and merges a form
file with a data file. I create the data file through a TransferText
command that stores the MSAccess record as a text delimited file.
I want my Access module to further handle this requirement:
If [NameOfAdditionalMacroNeeded] field from the data file is not
blank, find the macro by that name in the user’s MSWord normal.dot
and
execute it at the end of the merge.
Access groups are telling me to go to this group for help.
Can anyone help? Thank you. I'm a rookie at VBA, so please go easy
on
me!
Thank you Doug. I am currently exporting the data from the selected
record into a text file to merge with my Word mail merge doc. To use
your solution, would I still be merging, or populating my template,
with these fields in the text file? Or would I have to change my
technique and store the desired record in a temporary table in Access,
populating the template with that?
I have never worked with templates. Can you point me to some examples?