ADO, Recordset and two Access mdbs?

M

Major

I have two Access database,
and I want copy records from DB1 to DB2.

If have records from DB1mdb in ADODB.recordset,
could I insert records to DB2.mdb (Same table structure/name)
directly (whitout creating insert -sql statement)?
How?

I have two ADODB.connections, ofcourse.
I'm using VB6 and ADO...
 
J

Joe \Nuke Me Xemu\ Foster

Major said:
I have two Access database,
and I want copy records from DB1 to DB2.

If have records from DB1mdb in ADODB.recordset,
could I insert records to DB2.mdb (Same table structure/name)
directly (whitout creating insert -sql statement)?
How?

I have two ADODB.connections, ofcourse.
I'm using VB6 and ADO...

Unless ADO allows you to create a linked table in one of the MDBs,
you're hosed if you don't want to do it all yourself. Air-code:

dim f as field
conn2.begintrans
while not rs1.eof
rs2.addnew
for each f in rs1.fields
rs2(f.name).value = f.value
next f
rs2.update
rs1.movenext
wend
conn2.commit
 
B

Ben Taylor

Unless ADO allows you to create a linked table in one of the MDBs,
you're hosed if you don't want to do it all yourself. Air-code:

It doesn't. You can't modify the contents of the MSys~ tables. If only you
could, you could dynamically change linked tables, which would be a
beautiful feature of Access. But they don't *want* you to stick with Access
do they!

The only other alternative is to use an SQL Server DTS (before you start
jumping up and down that you haven't got SQL server, read on...):
If you DO have SQL Server - then just use Enterprise manager to design a
package with two Access connections. It will be faster than Joe's code
(which without DTS is the only method of doing it) and it doesn't matter one
bit that no SQL server databases are involved - some companies apparently
even buy SQL server even if they're not going to use it, just in order to
gain DTS capability.
If you haven't got SQL Server or they're 'too far away' on the network -
then you can create or get someone to send you (I could for one) the module
which SQL server outputs when you save a DTS as a Visual Basic module, then
you can look at the structure of it and modify it to fit your requirements.
You might have to dig around a bit for data type codes, although a good
sample would include a datatype of each field, like my_long, my_varchar,
etc.
You'd then just need to plonk it into your app and set a reference to
Microsoft DTSPackage object library (although you might need MSDE in order
to gain that DLL, but you can download MSDE for free).
 
B

Ben Taylor

Read my reply to Joe.
That said, having linked tables would be the far simpler solution if the
location of the databases isn't going to change.
 

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