siva_gk
asked on
Copy table between MS Access files using VB
I am having 2 MDB Access files say MDB_EMPTY and MDB_DATA which are having 1 table each.
Both are same tables say DB_ADDRESS. But DB_ADDRESS in MDB_EMPTY is having no data in it
and whereas MDB_DATA is having some data in it (say some 500 records).
Now I have to write a program in VB 6.0 to transfer those data from MDB_DATA to MDB_EMPTY.
Can anybody suggest in which way I have to do this?
Both are same tables say DB_ADDRESS. But DB_ADDRESS in MDB_EMPTY is having no data in it
and whereas MDB_DATA is having some data in it (say some 500 records).
Now I have to write a program in VB 6.0 to transfer those data from MDB_DATA to MDB_EMPTY.
Can anybody suggest in which way I have to do this?
How do I import/copy a database object from another database?
http://www.vbforums.com/showthread.php?t=409309
http://www.vbforums.com/showthread.php?t=409309
First you need to open the source database to copy the data in it by making instance of the ADO connection class, Using Excute method of the Connection object via action query INSERT INTO and specify the destination within the INSERT INTO string. Please see the code Snippet below.
I hope it will help you..
I hope it will help you..
'Using ADO Connection Class
'References Microsoft ActiveX Data Objects
Private Sub Command1_Click()
Dim MDB_Data As New ADODB.Connection, destination As String
destination = "d:\MDB_DATA.mdb" 'Destination of Data
MDB_Data.CursorLocation = adUseClient
MDB_Data.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\MDB_DATA.mdb" 'Source of Data
MDB_Data.Execute "INSERT INTO DB_ADDRESS IN '" & destination & "' SELECT * from DB_ADDRESS"
End Sub
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
thanks ema...
I already changed that in my ocde.
I already changed that in my ocde.
The only other way to "copy" a database object from one database to another with both being closed is to use a sql action query where you have to painstakenly use ADOX or such to retrieve the source objects table schema and recreate it in the other database. Then performa select into statement to copy the data. I honestly dont see why you cant have the 1 database opened via code for the easier methods I linked you to in my faq item.
This is from the first method in my faq and works without any problems having the destination database closed.
Open in new window