469,626 Members | 883 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

VBA: Access to Word Merge Help

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.



'************************************************* ***************************
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

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


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

End Sub
Nov 13 '05 #1
0 1386

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

By using this site, you agree to our Privacy Policy and Terms of Use.