Re: Creating a table from an Access Query by Cyberwolf
Cyberwolf
Thu Jun 23 14:16:12 CDT 2005
give it a try and let you know how it works.
Thanks,
Jim
"Doug Robbins" wrote:
> 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)
>
> --
> 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
> "Cyberwolf" <Cyberwolf@discussions.microsoft.com> wrote in message
> news:2D214359-EC18-4357-AE6E-C8C9CCFF6D22@microsoft.com...
> > 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,
> >
>
>
>