Running an Access Make Table Query using an Excel Macro

kkernohan

Board Regular
Joined
May 7, 2010
Messages
53
Hi,

I have an excel spreadsheet that is linked to an access database. I currently have to go into access and run a macro that I have created to update all of the tables and then go into excel and refresh all of my pivot tables/data tables.

What I would like to do is make it so that on the front page of my excel spreadsheet I have a button that will update the access tables automatically. I have taken a look around the internet but couldnt find a way to do this. There is only 4 tables to update so if its easier to just run the make tables seperately instead of the macro that works as well.

for example, I have 4 make table queries in Access, Table1, Table2, Table3, Table4.

I would like a macro in excel to run all four of these queries.

Thanks for the help.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Why do you need to run these queries to update the data?

Is more data being added?
 
Upvote 0
Code:
Set db = CreateObject("Access.Application")
db.Visible = False
db.OpenCurrentDatabase (dbloc)
db.DoCmd.RunMacro "mcr_import_data"

This silently opens your database (defined as dbloc which points to it as a Const) and runs whatever queries you have added to the Access macro named mcr_import_data.

Easy-peasy :-)
 
Upvote 0
Norie, yea it will update the data in the access queries which the pivot tables are run off of.

Chuckles, Thanks for the start! How do I 'select' the access database I want to open? do I have to place the directory/file name in place of dbloc?

thanks for the help
 
Upvote 0
Simply declare it:

Code:
Const dbloc As String = "J:\Operations\Reporting\chuckles1066\Schedules\db1.mdb"

Obviously replace my path with yours.
 
Upvote 0
How will it update the data?

Are the make table queries based on other queries?
 
Upvote 0
ah yes thanks chuckles. I think I'm almost there. Im getting a vba error saying "Run-Time error 3262: Could not lock table"

Do you know what this would be from?

thanks again for the help
 
Upvote 0
Norie - The make table queries are based on Oracle tables. Its going to basically just include the new data that has been added since the last time I have ran the update.

thanks
 
Upvote 0
ah yes thanks chuckles. I think I'm almost there. Im getting a vba error saying "Run-Time error 3262: Could not lock table"

Do you know what this would be from?

thanks again for the help

When you have the database open, it creates a record locking file in the background and is denoted by the file extension .ldb.

With the database closed have a look in the folder where it lives and see if there is still an .ldb file.

If there is, try deleting it and see if that cures your problem.
 
Upvote 0

Forum statistics

Threads
1,224,582
Messages
6,179,670
Members
452,936
Latest member
anamikabhargaw

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