Importing an Excel file into an Access table

bearcub

Well-known Member
Joined
May 18, 2005
Messages
731
Office Version
  1. 365
  2. 2013
  3. 2010
  4. 2007
Platform
  1. Windows
We have a process where the admins update an excel file and import it into a database that is used once a year.

I need to run a macro when Access initially opens up to import these tables. I don't want to append the existing tables I want to clear out the data and import the infomation for the Excel file

In regards to creating a macro, should I clear the contents of current table before I import the Excel table? I looked at the import options and I don't see where any of them delete the existing contents then copy over the new records.


If i have 7 or 8 tables to import upon opening, would this take a long period of item (the tables are all relatively small tables - less than 100 runs of information).

Thank you for your help,

Michael
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
You can clear all of the existing information out of your tables quickly and easily with a simple Macro.
Just create a Macro, and add the RunSQL action. And this is the line of code you want for that:
Code:
Delete [table1].* From [table1]
Where "table1" is the name of your table.

If you want to do multiple tables at once, just add additional RunSQL actions for each table (can be done all in the same macro).
If you do not like the warnings that you are about to delete data, you can use the SetWarnings action to turn those warnings off.

Then, all you need to do is to click on the macro to run it and clear that data from all the tables you want.
 
Upvote 0
Thank you Joe, this will work. I can create a macro on the open event to clear my tables then import the excel files, correct?
 
Upvote 0
Thank you Joe, this will work. I can create a macro on the open event to clear my tables then import the excel files, correct?
Yep. You can import the files in the same Macro.
 
Upvote 0
Thank you, I was hoping you would say that.
 
Upvote 0

Forum statistics

Threads
1,221,631
Messages
6,160,942
Members
451,679
Latest member
BlueH1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top