Importing Excel File and Comparing Tables in VBA

riggsd

Board Regular
Joined
Jan 29, 2003
Messages
143
I have two questions about tables.

1. I have a report generated from a SQL database that is being saved to the user's D: drive. The report is run from within Access, which calls the report using information the user entered in the Access form.

Once the report is saved as an Excel file, how do I import that file into Access using VBA? Because I have multiple users, the table has to be a temporary one, prefixed with the user's userid, which I'm getting using ENVIRON, followed by the Excel filename, i.e., riggsd_BSR_365_Maturity_Report.

2. Next, I need to run a query from the Access database, save it to another temporary table, prefixed with the user's userid, i.e., riggsd_Maturity_Report, then compare the two tables. The result of the compare needs to be exported to an Excel file and the temporary tables deleted. How do I do this in VBA?

Thanks in advance.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
DoCmd.TransferSpreadsheet

Look at the DoCmd.TransferSpreadsheet command in VBA. It's for importing or exporting and you can specify the table name for import. Are the queries you need to run static or dynamic? I.e. are they already built and will look for your imported table names? Also, if your tables are temporary, within VBA you can use the DoCmd.DeleteObject command to get rid of them.
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,700
Members
448,979
Latest member
DET4492

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