Link to home
Start Free TrialLog in
Avatar of BROOKLYN1950
BROOKLYN1950Flag for United States of America

asked on

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.

thanks.
ASKER CERTIFIED SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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)

JeffCoachman
...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...
;-)

JeffCoachman
Avatar of BROOKLYN1950

ASKER

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

<What is a PK field?>
A "Primary Key, ...it 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).

JeffCoachman
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.