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.
BROOKLYN1950Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeffrey CoachmanMIS 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
    rst.movenext
Loop

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

But I think you get the idea...

JeffCoachman
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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)

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

JeffCoachman
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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
0
mbizupCommented:
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

0
Jeffrey CoachmanMIS LiasonCommented:
<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
0
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.
0
Jeffrey CoachmanMIS LiasonCommented:
...ok...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.