Add records to tdfNew as TableDef

G

Guest

Access03/WinXP

I've looked through many samples and searches and *think* I have figured out
how to programmatically create a temporary table and create the necessary
fields, but I have yet to see how to add data to that table from a recordset.

If I have rs as a recordset with at least ContactID, DateCanceled as
selected fields, and have created tdfNew, appended to the database, and added
the fields ContactID and DateCanceled, how do I now add records to that table.

Typically, I have manually created the temporary table in the database
window in design view and then used a Do While Not rs.EOF loop to add records.

Do While Not rs.EOF
with tdfNew
.AddNew

The problem is that as soon as I type the period where the AddNew should be
inserted, AddNew is not one of the options.

Can anyone give me an example, or point me to a resource, where there is a
sample to programmatically create a table, add fields, and then populate said
table? Much appreciated!
 
G

Guest

Hi there,

You need to open a recordset on your new table to add records to it.

Set rsTarget = db.OpenRecordset("NewTableName")
Do While Not rs.EOF
With rsTarget
.AddNew
!ContactID = rs!ContactID
!DateCanceled = rs!DateCanceled
.Update
End With
rs.MoveNext
Loop

Jon.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top