Automatically Run VBA Code Upon Opening an Access Database
Access has the ability to run an Access object’s VBA code automatically whenever the object (form, report, etc.) is opened. It also has the ability to automatically open a designated form when the database launches. Combining these two means VBA code within a form can be automatically run when the database opens.
- Create a form, e.g. StartUp, that contains the organization name, logo and a main menu.
- Add a Form_Open subroutine containing the VBA code you want to run when the database opens.
- Test the code then save the form.
- Make the form automatically open when the database opens:
- [Click] FILE, OPTIONS
- [Click] CURRENT DATABASE, then choose StartUp from the DISPLAY FORM: list.
- [Click] OK.
The StartUp form will now automatically open when you next launch the database and the form’s Form_Open code will automatically run.
To circumvent automatically opening this form and running its code, hold down the SHIFT Key when launching the database.