Reputation: 842
I am trying to use a vba script to automatically import a few excell worksheets into access. However, if someone executes the script twice, the data gets added to the already existing table.
the code I am using is this:
DoCmd.TransferSpreadsheet _
acImport, _
acSpreadsheetTypeExcel9, _
"DB_AlarmTest", _
"C:\Data\PLC_MOBZ\Test\Import\DB_AlarmTest.xlsx", _
True
Is there a way to check wether or not this table already exists and if it does, delete or overwrite the existing table and replace it with the new table instead of just adding the values?
Upvotes: 1
Views: 524
Reputation: 1438
You can just drop the table before you run your import:
On Error Resume Next
CurrentDb.Execute "DROP TABLE DB_AlarmTest"
On Error GoTo 0
DoCmd.TransferSpreadsheet _
acImport, _
acSpreadsheetTypeExcel9, _
"DB_AlarmTest", _
"C:\Data\PLC_MOBZ\Test\Import\DB_AlarmTest.xlsx", _
True
Upvotes: 2