I have an auto exec script in access 2010 that executes as soon as the DB is loaded up by a user. The problem is, until that user enables macros, the script fails and gives an error because it's not allowed to run yet.
Is there a way to delay the autoexec until "enable macros" is selected, and then trigger it?
Or is there a way to trigger code without an autoexec, that is tied to the "enable macros" selection?
Enable the SHIFT key to allow the user to bypass the startup properties and the AutoExec macro. Disable the SHIFT key to prevent the user from bypassing the startup properties and the AutoExec macro. You can set this property by using a macro or VBA code.
I found How to force user to deal with the Security Warning when starting Access 2007?, which led me to this Microsoft support article.
From the Microsoft article:
You can use an AutoExec macro to test whether a database is trusted when you open the database. Additionally, the macro can open a form that displays a customized message to users if the database is not trusted. This message lets users know that the database must be enabled or trusted for the code to run successfully.
To create the AutoExec macro and the form, follow these steps:
- Create a new form in Design view.
- Add a text box or a label to the form, and then type the information that you want to display to the user.
- Save and then close the form.
- Create a macro, and then name the macro AutoExec.
- Show the Conditions column.
Type the following line in the Conditions column:
CurrentProject.IsTrusted = False
- In the Actions column, click OpenForm.
- In the Form Name box under Action Arguments, click the form that you created in step 1.
- Save and then close the macro.
When the database opens, the AutoExec macro starts and then tests the IsTrusted condition. If the database is not trusted by Access 2007, the macro opens the form that you specified in the "OpenForm" action of the macro.
The macro editor is different in 2010, but I was able to create an Autoexec macro that checked CurrentProject.IsTrusted = False
and then displayed my form. You can put a message on your form telling the user to enable macros.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With