By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,501 Members | 2,797 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,501 IT Pros & Developers. It's quick & easy.

VBA: Access to Word Merge Help

P: n/a
I have developed an app (in Access 2002) that dynamically creates a
table, and the fields in that table, for propagation based on the max
number of occurences in a reference table. Basically, it runs all the
necessary selects to produce a 'flat file' that is used with the mail
merge (in Word 2002).

My dilemma is, that the number of attributes will change daily, and I
had to create a static mail merge document because I'm not familiar
enough (at all) with Word objects to dynamcially create the merge with
a varying number of fields.

I'd like to be able to pass the largest number of occurrances, and
create the merge fields dynamically.

Below is the snippet that creates the table with a dynamic number of
attributes for each record. If someone could point me in the right
direction or offer a starting point on creating a mail merge the has
the same number of fields as the table, it would be much appreciated.

Sincerely,

beerman

'************************************************* ***************************
Sub mkTable(maxCount)

Dim db As Database
Set db = CurrentDb
Dim tbl As TableDef
Dim fld As Field
Dim idx As Index

Dim i As Long

i = maxCount

Set tbl = db.CreateTableDef("newTable")

With tbl
.Fields.Append .CreateField("varID", dbLong)
.Fields.Append .CreateField("varRefNum", dbLong)
.Fields.Append .CreateField("varName", dbText)
.Fields.Append .CreateField("varAmount", dbDouble)
.Fields.Append .CreateField("varFlag", dbText)

'Dynamically create the table fields based on the
max(CountOfOccurences)

For i = 1 To maxCount

.Fields.Append .CreateField("attrbA" & i, dbText, 150)
.Fields.Append .CreateField("attrbB" & i, dbText, 150)
.Fields.Append .CreateField("attrbC" & i, dbText, 150)
.Fields.Append .CreateField("attrbD" & i, dbText, 150)

Next i
End With

db.TableDefs.Append tbl
db.TableDefs.Refresh

RefreshDatabaseWindow

'For debugging purposes
'MsgBox "The table:" & tbl.Name & " was created"

End Sub
Nov 13 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.