You could identify each of the one row tables by assigning a bookmark to
them - e.g. Coverage, Lienholders, etc
The use something like
Dim myDataBase As Database
Dim myActiveRecord As Recordset
Dim i As Long
Dim dtable As Table, drow As Row
'Open a database
Set myDataBase = OpenDatabase("[Databasepath\filename.mdb]")
'Access the first record from a particular table
Set myActiveRecord = myDataBase.OpenRecordset("[tblNameforCoverageData]",
dbOpenForwardOnly)
'Add a table to the document with one row and as many fields as there are
in
the database table
Set dtable = ActiveDocument.Bookmarks("Coverage").Range.Tables(1)
'Loop through all the records in the table until the end-of-file marker
is
reached
Do While Not myActiveRecord.EOF
'Add a row to the table and populate the cells in that row with the
data
from the current
record
For i = 1 To myActiveRecord.Fields.Count
Set drow = dtable.Rows.Add
drow.Cells(i).Range.Text = myActiveRecord.Fields(i - 1)
Next i
myActiveRecord.MoveNext
Loop
'Then close the database
myActiveRecord.Close
'Access the first record from the next table
Set myActiveRecord =
myDataBase.OpenRecordset("[tblNameforLienHolderData]",
dbOpenForwardOnly)
'Add a table to the document with one row and as many fields as there are
in
the database table
Set dtable = ActiveDocument.Bookmarks("Lienholders").Range.Tables(1)
'Loop through all the records in the table until the end-of-file marker
is
reached
Do While Not myActiveRecord.EOF
'Add a row to the table and populate the cells in that row with the
data
from the current
record
For i = 1 To myActiveRecord.Fields.Count
Set drow = dtable.Rows.Add
drow.Cells(i).Range.Text = myActiveRecord.Fields(i - 1)
Next i
myActiveRecord.MoveNext
Loop
'Then close the database
myActiveRecord.Close
'etc.
Set myActiveRecord = Nothing
myDataBase.Close
Set myDataBase = Nothing
--
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, originally posted via msnews.microsoft.com
bryan said:
Hi Doug,
I appreciate the help but, need a little more to go on since I am new
on
dealing with adding tables and populating with data.
Lets say I have a 1 row table with 5 columns to start.
Will this row be for the headings only?
How do I then add the next row(s) and populate data, with adding
formfields
or by populating like you had indicated previously, and by identifying
which
table?
As much info as possible would be appreciated.
Thanks,
Bryan
:
I think that the better option might be to start with a one row table
for
each of those that might be required in the document, complete with
the
necessary row headings and with columns sized as required and in the
locations that you want them. Then use code to add rows to each table
as
required by the data that you want to insert into them. In the event
that
there is no data for some of the tables and they are thus not
required,
the
code could delete them.
--
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, originally posted via msnews.microsoft.com
Hi Doug,
Just want to reiterate this:
I will have multiple table on this document:
1 for coverage info, 1 for lienholders, and 1 for endorsement forms.
Others to follow.
If I am inserting a table as I am going along, how do I position
this
to a
certain spot on the document?
I suppose I could use a bookmark for the heading above each and then
insert
and populate.
Still the question,
Sizing of each cell..........
Is that determined by the data length?
Thanks,
Bryan
:
Tables are numbered starting from the beginning of the document.
Therefore,
Table(1) is the first table in the document.
The following code will populate a table with data from an Access
database:
Dim myDataBase As Database
Dim myActiveRecord As Recordset
Dim i As Long
Dim dtable As Table, drow As Row
'Open a database
Set myDataBase = OpenDatabase("c:\Access\Procurement Plan.mdb")
'Access the first record from a particular table
Set myActiveRecord = myDataBase.OpenRecordset("Currencies",
dbOpenForwardOnly)
'Add a table to the document with one row and as many fields as
there
are
in
the database table
Set dtable = ActiveDocument.Tables.Add(Range:=Selection.Range,
NumRows:=1,
numcolumns:=myActiveRecord.Fields.Count)
Set drow = dtable.Rows(1)
'Loop through all the records in the table until the end-of-file
marker
is
reached
Do While Not myActiveRecord.EOF
'Populate the cells in the Word table with the data from the
current
record
For i = 1 To myActiveRecord.Fields.Count
drow.Cells(i).Range.Text = myActiveRecord.Fields(i - 1)
Next i
'Add a new row to the Word table and access the next record
Set drow = dtable.Rows.Add
myActiveRecord.MoveNext
Loop
'The last row will be empty, so delete it
drow.Delete
'Then close the database
myActiveRecord.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, originally posted via msnews.microsoft.com
2 part question:
1st part) If I have a template with multiple tables, how do I
know
which
is
table(1), table(2), etc. in order to work with
2nd part) On this form, 1 table will be for insurance vehicle
coverage.
Column 1 is coverage, col 2 is effectvie date, col3 is amount,
col4
is
deductible.
As I am reading a database I want to populate col1 - col4
formfileds.
Since I will have more than 1 coverage, how can I add the next
row(s)
and
populate those fileds.
After this I list the endorsement forms: same principle as above
I'll have a 1 row table and then add row/columns for each
endorsement
found
Or for the second part would it be easier to have each table
(lets
say
with
8 rows) and then populate and once complete then check for empty
at
8
and
delete that row and continue up until not empty.
Thanks in advance fro the help in this 2 part question.
Bryan