WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ADO DAO
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Insert Rows From One Database to Another


Question:

I want to append to the end of an existing access table about 5000 rows on average from another access table in another access database. I have looked at many scripts on this site but I am apparently missing something. I would prefer to use a sql command to insert instead of a recordset unless I can bulk insert using the recordset. I have pasted the code I am trying to make work. The Access db's are in Access2, I believe. Is it possible to update this version of access using sql command line?

Here's a sample of the code I am trying to use:

cConn = "Provider=MicroSoft.Jet.OLEDB.4.0; Data Source = 'C:\Xware\Tables\TD\UMask.mdb'"
DB = ObjectOpen("ADODB.Connection")
DB.Open(cConn)
cSQL = "INSERT INTO TableX SELECT * FROM TableX IN 'C:\Xware\Tables\TD\XMask.mdb'"
DB.execute(cSQL)

DB.Close()
ObjectClose( DB )

Exit
Any help is appreciated.

Answer:

;Winbatch - inserting rows from one Access table to Another
;Stan Littlefield January 17, 2007
;////////////////////////////////////////////////////////////////////////
cSource=StrCat(DirScript(),"ncs.mdb")    ;substitute your own mdb
cTarget=StrCat(DirScript(),"ncstemp.mdb") ;same here
cTable = "CoopExt"
cConn = "Provider=MicroSoft.Jet.OLEDB.4.0; Data Source=%cTarget%;Jet OLEDB:Global Partial Bulk Ops=1"
;Global Partial Bulk Ops requires a primary key

oConn = CreateObject("ADODB.Connection")
oConn.CommandTimeOut = 0  ; gives the provider unlimited time to execute
nRecs=0
cSQL = 'INSERT INTO [%cTable%] SELECT * FROM [%cTable%] IN "" [%cSource%];'
oConn.Open(cConn)
oConn.Execute( cSQL,nRecs,-1 )
oConn.Close()
oConn=0
Message("Records Inserted",nRecs)
Exit

Article ID:   W17112
File Created: 2007:07:03:14:28:20
Last Updated: 2007:07:03:14:28:20