Insert a complete recordset into empty Access Table

I'm using ADODB to take a complete recordset from an external source (QuickBooks) and dump it into a table.

 I just cleared the existing table with
 REC.Open("Delete * From Employees", cn, CursorTypeEnum.adOpenDynamic, LockTypeEnum.adLockOptimistic)

I want to insert all the records from recordset into the employees table.

I tried the insert into...... but couldn't get all the records recognized.

Who is Participating?
Jeffrey CoachmanConnect With a Mentor MIS LiasonCommented:
There may be a more efficient way, but you can loop the recordset...

Do until rst.eof
    CurrentDB.execute "INSERT INTO YourTable(Field1, field2, Field3) VALUES(" & rst!Field1 & ", " & rst!Field2 & ", " & rst!Field3 & ")",dbfailonerror

You may have to adjust the SQL for string variables:   & "'" & rst!Field2 & "'" & 
...or Dates:   & "#" & rst!Field2 & "#" &

But I think you get the idea...

Jeffrey CoachmanMIS LiasonCommented:
Now if you are importing a PK field from QB to Access, ...create an kQB field in your Access table and insert the QB key values into this field. (do not set this field as AutoNumber)

Then create an Access table Autonumber key field, ...if you need one (or would like one, just to be sure of uniqueness).
In other words, you do not include the Access table Autonumber field in your INSERT code.
(it will autopupulate on its own as you insert the records)

Jeffrey CoachmanMIS LiasonCommented:
...and thinking a bit more about this...

Is this a one shot deal?

Because you may be able to "Link" the QB table into Access directly (presuming the QB table structure is compatible with Access tables)

Thus eliminate the need to do all of this loading and unloading of tables...

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to and use offer code ‘EXPERTS’ to get 10% off your first purchase.

BROOKLYN1950Author Commented:
this will be done multiple times a week, and or a number of different recordsets.

What is a PK field?  I will be importing multiple fields from quickbooks at a time
How are you opening your QuickBooks recordset?  Are you using a linked table?

If you have set up a linked table to quickbooks, you can simply do this:

Dim strSQL as string
strSQL = "INSERT INTO YourAccessTable (Field1, Field2, Field3 ....) SELECT Field1, field2, Field 3... FROM YourLinkedTable"
CurrentDB.Execute strSQL, dbFailonError

Open in new window

Jeffrey CoachmanMIS LiasonCommented:
<What is a PK field?>
A "Primary Key, is the unique record ID (for example CustomerID, or InvoiceID)

But consider what I posted, and mbizup presented an example of:
"Linking" to the quickbooks data.

Instead of constantly clearing and reloading a table, just link the QuickBooks table into Access.
Then use the linked table as if it was  a local table in Access.
...or (using mbizups suggestion) insert the QB linked data into the access table. (if the linked table presents performance issues.)

In other words, it is not clear to us why you are having to keep clearing, then loading this Access table (or these Access tables).

BROOKLYN1950Author Commented:
After playing with this, I realized I didn't want to delete the entire table as it deleted the Ids for the records so I am back to looping through the record set and assigning the field values to the recordset values.
Jeffrey CoachmanMIS LiasonCommented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.