Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.tables
Romine Romine is offline
external usenet poster
 
Posts: 1
Default Positioning Data in Indivisual Cells within a Table using VBA

I am importing data from an AS/400 using OLE DB/ADO and wish to
populate a table with data.

I am reading a Primary file which has header information, and I need
to load detail from two additional files into the Table. The number
of rows within the table must be variable.

I would like to control loading the table by cell. For example, load
Name in Row 1, Column 1, Amount #1 in Row 1, Column 2, Amount #2 in
Row 1, Column 3, Total in Row 1, Column 4....then read the next record
and start loading in Row 2...and so on.

So, my question is this; How do I load data into cells of a table and
allow the table to be a variable length?

Thanks,

Romine

  #2   Report Post  
Posted to microsoft.public.word.tables
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Positioning Data in Indivisual Cells within a Table using VBA

Use a Catalog or in Word XP and later, it is calle Directory, type mail
merge.

Here is how you would create a table in a document and insert the data from
an Access table into the rows of that table:

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

"Romine" wrote in message
oups.com...
I am importing data from an AS/400 using OLE DB/ADO and wish to
populate a table with data.

I am reading a Primary file which has header information, and I need
to load detail from two additional files into the Table. The number
of rows within the table must be variable.

I would like to control loading the table by cell. For example, load
Name in Row 1, Column 1, Amount #1 in Row 1, Column 2, Amount #2 in
Row 1, Column 3, Total in Row 1, Column 4....then read the next record
and start loading in Row 2...and so on.

So, my question is this; How do I load data into cells of a table and
allow the table to be a variable length?

Thanks,

Romine



  #3   Report Post  
Posted to microsoft.public.word.tables
Marco Napoli Marco Napoli is offline
external usenet poster
 
Posts: 1
Default Positioning Data in Indivisual Cells within a Table using VBA

Is there a way to choose a place to add a Table by code without using
Bookmarks?

--

Peace in Christ
Marco Napoli
http://www.ourlovingmother.org


"Doug Robbins - Word MVP" wrote in message
...
Use a Catalog or in Word XP and later, it is calle Directory, type mail
merge.

Here is how you would create a table in a document and insert the data
from an Access table into the rows of that table:

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

"Romine" wrote in message
oups.com...
I am importing data from an AS/400 using OLE DB/ADO and wish to
populate a table with data.

I am reading a Primary file which has header information, and I need
to load detail from two additional files into the Table. The number
of rows within the table must be variable.

I would like to control loading the table by cell. For example, load
Name in Row 1, Column 1, Amount #1 in Row 1, Column 2, Amount #2 in
Row 1, Column 3, Total in Row 1, Column 4....then read the next record
and start loading in Row 2...and so on.

So, my question is this; How do I load data into cells of a table and
allow the table to be a variable length?

Thanks,

Romine




  #4   Report Post  
Posted to microsoft.public.word.tables
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Positioning Data in Indivisual Cells within a Table using VBA

Yes, but how would the location be determined?

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

"Marco Napoli" wrote in message
...
Is there a way to choose a place to add a Table by code without using
Bookmarks?

--

Peace in Christ
Marco Napoli
http://www.ourlovingmother.org


"Doug Robbins - Word MVP" wrote in message
...
Use a Catalog or in Word XP and later, it is calle Directory, type mail
merge.

Here is how you would create a table in a document and insert the data
from an Access table into the rows of that table:

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

"Romine" wrote in message
oups.com...
I am importing data from an AS/400 using OLE DB/ADO and wish to
populate a table with data.

I am reading a Primary file which has header information, and I need
to load detail from two additional files into the Table. The number
of rows within the table must be variable.

I would like to control loading the table by cell. For example, load
Name in Row 1, Column 1, Amount #1 in Row 1, Column 2, Amount #2 in
Row 1, Column 3, Total in Row 1, Column 4....then read the next record
and start loading in Row 2...and so on.

So, my question is this; How do I load data into cells of a table and
allow the table to be a variable length?

Thanks,

Romine






Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
want cells in a table to copy data from cells in another table Conrad D. Farner Tables 2 September 27th 06 04:21 PM
MS Word: select cells range and duplicate same data in all cells clarice Microsoft Word Help 0 June 1st 06 04:19 AM
Pasting the Same Data into multiple cells of a table DEB04 Tables 1 November 18th 05 08:11 PM
Table Cells act as if there is more info to the right of the data WIM4246 Tables 0 August 2nd 05 04:55 PM
Automatic calculation as data is entered into table cells Gerry Duggan Microsoft Word Help 1 February 23rd 05 10:57 PM


All times are GMT +1. The time now is 06:19 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"