Locked lesson.
About this lesson
Create a command button to open a table or query and make it the Startup form when the database opens.
Exercise files
Download this lesson’s related exercise files.
Services_39 - Start Open Tables and Queries with VBA, Startup Form.accdb1.8 MB Services_39 - Open Tables and Queries with VBA, Startup Form.accdb
1.8 MB
Quick reference
Open Tables and Queries with VBA, Startup Form
Steps
Command button to Open a Table
- Go to the Design View of your form
- Choose the Button tools from Controls on the DESIGN ribbon of FORM DESIGN Tools
- Click on your form where you want the button
- Cancel the Wizard if it comes up
- Open the Property Sheet if it is not showing by pressing Alt-Enter
- On the Other tab, give your button a good Name (i.e.: cmd_OpenMyTablename)
WHERE MyTablename is the name of your table - In the Event tab, in the Click event for the button, type
[ (to choose [Event Procedure]) - Click the Builder button, ... or press Ctrl-F2 for the builder
- In the code, type:
- From the menu, choose Debug, Compile then Save.
Command button to Open a Query
- Go to the Design View of your form
- Choose the Button tools from Controls on the DESIGN ribbon of FORM DESIGN Tools
- Click on your form where you want the button
- Cancel the Wizard if it comes up
- Open the Property Sheet if it is not showing by pressing Alt-Enter
- On the Other tab, give your button a good Name (i.e.: cmd_OpenMyQueryname)
WHERE MyQueryname is the name of your query - In the Event tab, in the Click event for the button, type
[ (to choose [Event Procedure]) - Click the Builder button, ... or press Ctrl-F2 for the builder
- In the code, type:
- From the menu, choose Debug, Compile then Save.
Specify a Startup Form
- From the menu, choose FILE, Options, Current Database.
- Drop the choices for Display Form and choose the form you want to automatically open (i.e., f_MAINMENU).
- When you close the database and open it again, that form will be displayed.
Change Company Information
- To customize the database for your company, click My Company, and change the Company name in the MyCompany table.
Concepts
qListOfObjects.
This is a new query in the database that shows you a list of the database objects when you open it.
Analyzer for Microsoft Access
To download the latest version of the free Analyzer for Microsoft Access, go to CodePlex, which is Microsoft's sharing site for developers.
Login to downloadLesson notes are only available for subscribers.