Question

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?

Was it helpful?

Solution

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:

  1. Create a new form in Design view.
  2. Add a text box or a label to the form, and then type the information that you want to display to the user.
  3. Save and then close the form.
  4. Create a macro, and then name the macro AutoExec.
  5. Show the Conditions column.
  6. Type the following line in the Conditions column:

    CurrentProject.IsTrusted = False

  7. In the Actions column, click OpenForm.
  8. In the Form Name box under Action Arguments, click the form that you created in step 1.
  9. 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top