Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
; setup constants... acTable = 0 acImport = 0 SourceMDBName = "C:\Data\Access\LogFile.mdb" DestinationMDBName = "C:\Data\Access\Naruni.mdb" SourceTableName = "Log Table" DestinationTableName = "New Log Table" ; open access... accessDB = ObjectOpen("Access.Application") ADB = accessDB.Application dbname = DestinationMDBName ADB.OpenCurrentDatabase(dbname) ADB.Visible = @FALSE ADB.UserControl = @FALSE ; reference the DOCmd method... ADBCmd = ADB.docmd ; set up the ref to tabledefs collection... db = accessDB.currentdb tdefs = db.tabledefs tlist = @FALSE ; loop thru the table defs... For t = 0 To tdefs.count-1 ; setup the ref for this table in the collection... table = db.tabledefs(t) ; check to see if the table already exists... If table.name == DestinationTableName tlist = @TRUE Break EndIf ObjectClose(table) Next ; if table exists delete it... If tlist Then ADBCmd.DeleteObject(acTable, DestinationTableName) ; this will copy the whole table from the source to the destination... ADBCmd.TransferDatabase (acImport, "Microsoft Access", SourceMDBName, acTable, SourceTableName, DestinationTableName) Drop(tlist) ObjectClose(tdefs) ObjectClose(db) ObjectClose(ADBCmd) ObjectClose(ADB) ObjectClose(accessDB) Message("Debug", "All Done") Exit
In ADO you could use:
DELETE * FROM Table1 INSERT INTO Table1 SELECT * FROM Table2 [ IN database ]I believe if you set Errormode off prior to the Delete Statement, then set it back on after, you will not have to check that the table exists.
Notes: The IN Keyword is MSAccess specific, and it allows you to directly import into a table from either another Access Table or a supported ISAM.
INSERT INTO TABLE1 SELECT * FROM filename IN [dBase IV;Database=C:\temp];if both the dBase IV file and TABLE1 had the same structure; if you were doing it from a text file you would have an entry in schema.ini - or it works with Excel or HTML.
Important NOTE: after Office 2000, Microsoft turned off all ISAM support except read-only for the Paradox/dbase ISAMS. So if you were using the Jet 4.0 Provider with Extended Properties=dBase III, you cannot update; you either have to install the BDE (Borlan Database Editor??) or use a workaround.
Article ID: W16099
File Created: 2004:03:30:15:42:52
Last Updated: 2004:03:30:15:42:52