Re: Tables and inserting rows
- From: "Doug Robbins - Word MVP" <dkr@xxxxxxxxxxxxxxxxxx>
- Date: Sat, 16 May 2009 08:13:56 +1000
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
"bryan" <bryan@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:802207C3-5BF4-418E-A767-5B2764C1491A@xxxxxxxxxxxxxxxx
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
"Doug Robbins - Word MVP" wrote:
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
"bryan" <bryan@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:95241AB9-BF58-4099-B766-9D0C5E73886F@xxxxxxxxxxxxxxxx
>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
.
- Follow-Ups:
- Re: Tables and inserting rows
- From: bryan
- Re: Tables and inserting rows
- References:
- Tables and inserting rows
- From: bryan
- Re: Tables and inserting rows
- From: Doug Robbins - Word MVP
- Re: Tables and inserting rows
- From: bryan
- Tables and inserting rows
- Prev by Date: Re: Code for Checkboxes
- Next by Date: Capturing in code the Rtf and Html of a merge document
- Previous by thread: Re: Tables and inserting rows
- Next by thread: Re: Tables and inserting rows
- Index(es):
Relevant Pages
|
Loading