Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

When an Access application begins, there will be actions you want to do to ensure your users have the best experience possible. The object names are provided so you can easily examine them in the ­Northwind 2.0 Starter Edition database.

An AutoExec macro runs when the Access application opens to initialize the application. Access also provides a database setting for the name of a form to open at startup. It can be found here:

File > Options > Current Database > Application Options > Display Form

If a starting form can be identified, why not just use that instead of an AutoExec macro? The reason is Trusted Locations which require you to enable content.

Message bar for enabling content

An AutoExec macro (it must be named AutoExec) is the only code that can execute when the trusted location security warning occurs, allowing you to handle it gracefully. A recommended practice is to handle all errors and warnings to ensure the application executes correctly. This is often referred to as defensive programming. Using an AutoExec macro at startup is the best defense. For more information, on trusted locations, see Northwind 2.0 Starter Edition: a brief introduction to VBA.

Once the AutoExec macro has determined the database is in a trusted location it will call a Visual Basic for Applications (VBA) function in modStartUp that is called StartUp. This module will determine the events that need to take place to provide the user with the best possible experience. These activities are performed by the StartUp module in the following order:

  1. Instantiate the global error handler from clsErrorHandler.

  2. Set the application title. For more information, see Application.AppTitle property.

  3. Make sure the Navigation Pane is visible and set to the correct category.

  4. Show the frmWelcome screen if appropriate.

  5. Get your Windows UserID to see if you are in the Employee table. For more information, see Environ function and DLookup Function.

  6. If a user isn’t in the Employee table, open frmCredentials so you can enter your First Name, Last Name and Title.

  7. If a user is in the Employees table, open frmLogin and select your name in the Employee combo box. You can choose anyone you want from the list.

frmWelcome displays the first time the application opens. The form shows you how to navigate within the application, how it is laid out, and how to get more information on a topic.

There is a checkbox at the bottom of the form which says, "Show this form when the database is opened". If you uncheck this, it will not show when the database is opened again. This setting is kept in the table, SystemSettings.

To personalize your experience, the database prompts you to enter your first and last name along with a job title. When you have done that, click Add Me to be added to the Employees table and then frmMainMenu is opened. 


Why do you want to be added to the Employees table? One reason is, there are audit data macros on the tables. These macros capture who added or modified a record and when. These fields allow you to see the impact of your actions in the tables. For more information, see Create a data macro and Data macro events.

In a production application, you would only be able to login as yourself for security purposes. But we allow you to login as any employee you choose. Why are we doing that?

As the developer, you may need to be able to test or experience the application from a different perspective. Users may have different privileges – things they are allowed to do and see or not do and not see. Think about a Human Resource department. There may be 15 employees in that department. You probably don’t want 15 people to be able to enter or change people’s salaries. Your organization might have one person who can change the salary and a second person to approve it. In the development environment you should test that the controls you put in place (who can do what) are working.

See Also

Northwind 2.0 Starter Edition

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

Was this information helpful?

What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×