Re: Tables and inserting rows
- From: bryan <bryan@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 29 May 2009 07:43:01 -0700
The tables are in a seperate document which I auto attached right away after
combo box indicating which vehicle so the info of coverages, leinholder, and
endorsements would populate for that 1 vehicle.
A seperate document for a variety of reasons.
Like I said it works great but, now they would like to select multiple
vehicles. With that in mind I need to attach multiple doc's.
I have played with this a bit by having a form field at each spot where I
want the table and then cursor to that field and then build the table like:
ActiveDocument.Bookmarks("Cov").Range.Fields(1).Result.Select
Set dtable = ActiveDocument.Tables.Add(Range:=Selection.Range,
NumRows:=1, numcolumns:=4, DefaultTableBehavior:=wdWord9TableBehavior, _
AutoFitBehavior:=wdAutoFitContent)
dtable.AutoFormat ApplyBorders:=False, ApplyShading:=False,
AutoFit:=False
Set drow = dtable.Rows(1)
etc.
Cov would be renamed with each insertion then positioned to to build the
table.
This will work but, I was hoping to rename the actual bookmark within the
table so that formatting of the cells I could set and space out better using:
Set dtable = ActiveDocument.Bookmarks("Cov").Range.Tables(1)
Is it possible to rename the bookmark or do I have to use the other option
of having a form field to position to and then create a table?
Thanks,
Bryan
"Doug Robbins - Word MVP" wrote:
I am trouble by your statement "I have the main template and then am.
inserting a document which has all the
tables"
I would have everything set up in the template and if they want to create a
document for another unit, they should be creating a new document from that
template.
--
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:A9382DC7-310A-43B0-901D-CD71832D37CC@xxxxxxxxxxxxxxxx
Hi Doug,
Works great but, now users want to add a twist and I am having a problem
with this.
I have the main template and then am inserting a document which has all
the
tables.
Initially it was set that I used a combo box at first to ge the unit
desired
and then inserted the doc and got the coverage, lienholder, and endorsment
info for that unit and populated the table.
Now they want to have it work where they can select multiple units and do
the same.
The problem is that when the second unit adds a document and then
populates
table info, it just adds onto the first rather than on the new added doc.
Set dtable = ActiveDocument.Bookmarks("Coverage").Range.Tables(1)
Is there a way to rename this bookmark?
The bookmark is inside the table of the document which gets attached.
Thanks,
Bryan
"Doug Robbins - Word MVP" wrote:
It would be easiest just to have each one row table with the column
heading
names inserted into the document/template and have it identified by a
bookmark (rather than try and do something with autotext). Having the
table
itself allows equally well the sizing of the columns.
--
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:93349F73-CE9F-43A0-A2CC-34236794AC8B@xxxxxxxxxxxxxxxx
See if I have this striaght to get started:
For each table I will have a bookmark for placement. Am I creating the
table
as I go or do I want a 1 row table in autotext with the headings to
insert
at
bookmark and then add rows to that?
Having the one row as autotext would allow for sizing of columns. If
using
autotext for the 1 row table, do I want the headings in this row?
Again, I truly appreciate all the help on this.
Thanks,
Bryan
"Doug Robbins - Word MVP" wrote:
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" <bryan@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:B636F19A-4A67-4C4C-938C-B6E658C2CAB1@xxxxxxxxxxxxxxxx
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
"Doug Robbins - Word MVP" wrote:
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
- Follow-Ups:
- Re: Tables and inserting rows
- From: Doug Robbins - Word MVP
- Re: Tables and inserting rows
- Prev by Date: Insertion of a field code at the end of each paragraph
- Next by Date: Re: VBA to Restart Numbering at a number other than 1
- Previous by thread: Insertion of a field code at the end of each paragraph
- Next by thread: Re: Tables and inserting rows
- Index(es):
Relevant Pages
|