How to make two queries run when a access database is opened

TTR9000

New Member
Joined
Nov 3, 2003
Messages
29
I am trying to make this database as automated as possible and I cant figured out how to make these to queries run when there database is open. Both of the queries make a table and I cant figure out how to make the errors message that pop up telling me that I am about to paste 5000 records to disappear automatically. So I need lots of help.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Re: How to make two queries run when a access database is op

If you go into the Tools drop down menu, select the Startup option. If you select a form from the Display Form/Page option, Access will automatically open to this form.

So...
If you create a form, and put code in the On Open or On Load event (i.e. code to run your queries), whenever this form is opened it will run your code. Then select this form to open at startup using the method described in the above paragraph. So as Access is opened, the form will open, and your code will kick off running your queries.

Lastly, to hide your warning messages use code (in VBA format):
DoCmd.SetWarnings False
 
Upvote 0
Re: How to make two queries run when a access database is op

Another way is to create a macro named "Autoexec" and place the query commands in it. This macro runs on database startup.

HTH,
CT
 
Upvote 0
Re: How to make two queries run when a access database is op

Sub autoexec()
DoCmd.OpenQuery "proto mat", , acReadOnly
End Sub

that is what i have as a macro and it is not running when the database starts up


and i went to create a form and i did not see a on open or on load event
 
Upvote 0
Re: How to make two queries run when a access database is op

I'm afraid you are confused. You have entered code which I presume is either in the form or in modules? To run the code that you have:

Go to Macros - > Create a New Macro

Under the action select RunCode. It will give you an option to enter the function name. Type Autoexec.

Save the macro as AutoExec.

Go into Modules -> New Module

Paste your existing code and save the module (ie module1).

Next time you enter the db, the code should run!
 
Upvote 0
Re: How to make two queries run when a access database is op

I am not new to access but am new to macros and vb in access. Ok so I made the macro and module like you said and when I open the db now a error message comes up which says
microsoft access cant find the name 'Autoexec' you entered in the expression you may have specified a control that wasn't on the current object without specifying the correct form or report context

and then it tells me that the action failed

what do you think went wrong?

Thanks for all of your help.
 
Upvote 0

Forum statistics

Threads
1,221,668
Messages
6,161,163
Members
451,687
Latest member
KENNETH ROGERS

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