You insert VBA commands by typing them into the appropriate place in the Module window. This, of course, requires some knowledge of VBA. Access provides online Help to assist you in writing VBA code. The Visual Basic Editor also helps you with hints that help you complete a command accurately. If you have entered a command incorrectly, the Editor notifies you of the error and may suggest ways of correcting the problem. One of the most useful VBA objects you'll encounter in writing VBA code is the DoCmd object, which represents Access commands. You can use DoCmd in your commands to perform basic operations, like opening tables, reports, and forms.
Write a VBA Command to Open a Table
|
Click the Modules window to activate it.
|
|
Click a blank line after the Sub ProcedureName command in the Modules window.
|
|
Type DoCmd. Make sure you include the period.
|
|
Double-click OpenTable in the list box that appears, and then press the Spacebar.
|
|
As indicated by the hints supplied by the Editor, type the name of a table from the current database. Make sure you enclose the name in quotation marks.
|
|
Type a comma.
|
|
Double-click acViewNormal to open the table in Normal view.
|
|
Type a comma.
|
|
Double-click acReadOnly to open the table in Read-only mode.
|
|
Press Enter to add a new blank line below the command.
|
|