Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.tables
BrownKoW
 
Posts: n/a
Default How do I fill a Word table from data source?

I have a Word document/form created with Word tables. I need to
electronically fill that form from an external data source before printing.
Can it be done?
  #2   Report Post  
Posted to microsoft.public.word.tables
Doug Robbins - Word MVP
 
Posts: n/a
Default How do I fill a Word table from data source?

Have you considered using mailmerge?

Or the following macro will add a table to a document and populate it with
data from a table in 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

"BrownKoW" wrote in message
...
I have a Word document/form created with Word tables. I need to
electronically fill that form from an external data source before
printing.
Can it be done?



  #3   Report Post  
Posted to microsoft.public.word.tables
Timo Horn
 
Posts: n/a
Default How do I fill a Word table from data source?

Can you please tell me if this also can be done with an adp, and based on a
view or stored procedure.
and when i would like to use it in a mailmerge can i use this to fill a
table on every page ?

Thanxs
  #4   Report Post  
Posted to microsoft.public.word.tables
Doug Robbins - Word MVP
 
Posts: n/a
Default How do I fill a Word table from data source?

What's adp?

Please explain in more detail what you are trying to do.

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

"Timo Horn" Timo wrote in message
...
Can you please tell me if this also can be done with an adp, and based on
a
view or stored procedure.
and when i would like to use it in a mailmerge can i use this to fill a
table on every page ?

Thanxs



  #5   Report Post  
Posted to microsoft.public.word.tables
Timo Horn
 
Posts: n/a
Default How do I fill a Word table from data source?

it s an access project, linked to an sql database, perhaps it helps.

Thanxs

Timo

"Doug Robbins - Word MVP" wrote:

What's adp?

Please explain in more detail what you are trying to do.

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

"Timo Horn" Timo wrote in message
...
Can you please tell me if this also can be done with an adp, and based on
a
view or stored procedure.
and when i would like to use it in a mailmerge can i use this to fill a
table on every page ?

Thanxs






  #6   Report Post  
Posted to microsoft.public.word.tables
Doug Robbins - Word MVP
 
Posts: n/a
Default How do I fill a Word table from data source?

If by a view, you mean an Access Query, that can be used as a datasource for
a mail merge in Word. If you want to use mail merge to display the
information in a table in a Word document, you would use a Directory type
mailmerge main document in which you have a single row table into the cells
of which you insert the merge fields corresponding to the fields in the
Access Query or Table. When you execute that merge to a new document, it
will contain a table with a row for data for every record in the datasource.

The following vba code will create a table in a Word documnet and populate
its cells with data from a table or query in 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

"Timo Horn" wrote in message
...
it s an access project, linked to an sql database, perhaps it helps.

Thanxs

Timo

"Doug Robbins - Word MVP" wrote:

What's adp?

Please explain in more detail what you are trying to do.

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

"Timo Horn" Timo wrote in message
...
Can you please tell me if this also can be done with an adp, and based
on
a
view or stored procedure.
and when i would like to use it in a mailmerge can i use this to fill a
table on every page ?

Thanxs






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
Does Word have a QuickCorrect/Quick Word option like WordPerfect? CW New Users 2 December 20th 05 06:54 PM
How do I set right and left alignment on the same line in Word? Matador Page Layout 1 November 9th 05 09:32 PM
More Info On Directory Merge Please JohnB Mailmerge 14 September 6th 05 01:27 PM
Specific Email Merge w/ Specific Attachements Mark B Mailmerge 9 February 21st 05 06:10 AM
merging Word 2000 data source and word 2003 envelopes Jini Mailmerge 1 December 2nd 04 11:48 PM


All times are GMT +1. The time now is 11:46 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"