J
JKarchner
Ok i would like to import data from an access database table into a table in
a microsoft word file. The table is already created and i would to just
insert the data into that table. Here is the tricky part: each record
should have a new table. The table created is a template for how all the
tables should look. Is there a way to to have it so that a new table is
copied from the template and the data is inserted into it. Or will i have to
create a table for each record on my own. I was given some sample code to
use with it and would like to know if it is correct, and also some tips to go
about using it. The source of my code was not sure if the code for the table
was correct, and also i would assume that cell(#,#) is (row,column).
Sub GetDataFromDataBase()
'allocate memory for the database object as a whole and for the active record
Dim myDataBase As Database
Dim myActiveRecord As Recordset
'Open a database
Set myDataBase = OpenDatabase("C:\DataBaseFolder\Database.mdb")
'Access the first record from a particular table
Set myActiveRecord = myDataBase.OpenRecordset("Table_1", dbOpenForwardOnly)
'Loop through all the records in the table until the end-of-file marker is
reached
Do While Not myActiveRecord.EOF
'If field #1 contains a non-zero value,
'insert the value of field #2 into the document
'after the current cursor or selection location
If myActiveRecord.Fields("Field_1") <> 0 Then
'this will put the data after the cursor, you have to set it up so that
it goes in the correct field in your table, if you want it in a table, i
believe it's selection.tables(#).cell(#,#)
selection.tables(#).cell(#,#) myActiveRecord.Fields("Field_2")
End If
'access the next record
myActiveRecord.MoveNext
Loop
'Then close the database
myActiveRecord.Close
myDataBase.Close
End Sub
Thank you for any help that you can give.
a microsoft word file. The table is already created and i would to just
insert the data into that table. Here is the tricky part: each record
should have a new table. The table created is a template for how all the
tables should look. Is there a way to to have it so that a new table is
copied from the template and the data is inserted into it. Or will i have to
create a table for each record on my own. I was given some sample code to
use with it and would like to know if it is correct, and also some tips to go
about using it. The source of my code was not sure if the code for the table
was correct, and also i would assume that cell(#,#) is (row,column).
Sub GetDataFromDataBase()
'allocate memory for the database object as a whole and for the active record
Dim myDataBase As Database
Dim myActiveRecord As Recordset
'Open a database
Set myDataBase = OpenDatabase("C:\DataBaseFolder\Database.mdb")
'Access the first record from a particular table
Set myActiveRecord = myDataBase.OpenRecordset("Table_1", dbOpenForwardOnly)
'Loop through all the records in the table until the end-of-file marker is
reached
Do While Not myActiveRecord.EOF
'If field #1 contains a non-zero value,
'insert the value of field #2 into the document
'after the current cursor or selection location
If myActiveRecord.Fields("Field_1") <> 0 Then
'this will put the data after the cursor, you have to set it up so that
it goes in the correct field in your table, if you want it in a table, i
believe it's selection.tables(#).cell(#,#)
selection.tables(#).cell(#,#) myActiveRecord.Fields("Field_2")
End If
'access the next record
myActiveRecord.MoveNext
Loop
'Then close the database
myActiveRecord.Close
myDataBase.Close
End Sub
Thank you for any help that you can give.