473,385 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.

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
0 1568

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Ecohouse | last post by:
I have a computer with XP on it. I loaded Office 97 first because I needed Access 97 for some work. I then loaded Office 2000. Everything seemed to be running fine. But I have come across a few...
3
by: Andy Davis | last post by:
I have set up a mail merge document in Word 2003 which gets its data from my Access 2000 database. I want to set up a button on a form that: 1. runs the query to provide the dat for the merge...
0
by: Linda Cacina | last post by:
Hello all you fine folks, Here is some code I am using to merge data from a single record Access 2K3 table into a NEW word document based on a pre-defined Word merge template doc. All I want to...
8
by: Ron B | last post by:
Help!!! What am I doing wrong? I am working with Office 2003 and am trying to create a command button on an Access form that will create a mail merge in Word from an Access table. I want to...
8
by: babyangel43 | last post by:
Hello, I have a query set up in Access. I run it monthly, changing "date of test". I would like this query to be merged with a Word document so that the cover letter is created in Word, the fields...
1
by: kayberrie | last post by:
I want to write a VBA mail merge code. I want to link the code/macro/dohicky to a nifty little button so it makes life easy. I think I can handle the button part, the code part - not so much. I know...
1
by: akaess | last post by:
I am trying to merge information from the the database into word documents using the following methods but it keeps giving the error 91: Object Variable or With Block Variable not set. could anybody...
4
by: Kelii | last post by:
Access 2003, Windows XP SP2 I have an application that generates a word document populated with a variety of fields from Access tables. The word document is generated when the user presses a...
1
by: lchomany | last post by:
Can anyone tell me what the compiled error would be here? Saying "User-defined type not found" and highlighted objWord As Word.Document in yellow ______________________________ Private Sub...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.