Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2005

Tip: Looking for answers? Try searching our database.

Creating a table from an Access Query

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Cyberwolf - 23 Jun 2005 15:20 GMT
How can I go about creating a table in a Word Document at a specific place
from a query.  The number of rows will vary based on how many records were
input that matches that specific queries criteria.  I would imagine the
bookmark in Word would come into play in the Word document, but I have been
unsuccessful in creating separate rows in the table.  The columns would not
change.

Thanks,
Doug Robbins - 23 Jun 2005 20:01 GMT
Use something like the following:

Dim myDataBase As Database
Dim myActiveRecord As Recordset
Dim i As Long, j As Long, col As Long
'Open a database
Set myDataBase = OpenDatabase("C:\Procurement\Procurement Plan.mdb")
'Access the first record from a particular table
Set myActiveRecord = myDataBase.OpenRecordset("Motors", dbOpenForwardOnly)

' Get the number of Fields in the Query
j = myActiveRecord.Fields.Count - 1
' Start inserting data in Row 2 of the table
i = 2
'Loop through all the records in the table until the end-of-file marker is
reached
Do While Not myActiveRecord.EOF
' Insert the data into the cells
       For col = 0 To j
   ActiveDocument.Tables(1).Cell(i, col + 1).Range.InsertAfter
myActiveRecord.Fields(col)
   Next col
   i = i + 1
   ActiveDocument.Tables(1).Rows.Add
'access the next record
   myActiveRecord.MoveNext
Loop
'Then close the database
myActiveRecord.Close
myDataBase.Close

You will need a reference to the DAO object library (Tools>References in the
VBE)

Signature

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

> How can I go about creating a table in a Word Document at a specific place
> from a query.  The number of rows will vary based on how many records were
[quoted text clipped - 6 lines]
>
> Thanks,
Cyberwolf - 23 Jun 2005 20:16 GMT
give it a try and let you know how it works.

Thanks,

Jim

> Use something like the following:
>
[quoted text clipped - 40 lines]
> >
> > Thanks,
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.