[ Team LiB ] Previous Section Next Section

Writing VBA Commands

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

graphics/1_icon.jpg

Click the Modules window to activate it.

graphics/2_icon.jpg

Click a blank line after the Sub ProcedureName command in the Modules window.

graphics/3_icon.jpg

Type DoCmd. Make sure you include the period.

graphics/4_icon.jpg

Double-click OpenTable in the list box that appears, and then press the Spacebar.

graphics/5_icon.jpg

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.

graphics/6_icon.jpg

Type a comma.

graphics/7_icon.jpg

Double-click acViewNormal to open the table in Normal view.

graphics/8_icon.jpg

Type a comma.

graphics/9_icon.jpg

Double-click acReadOnly to open the table in Read-only mode.

graphics/10_icon.jpg

Press Enter to add a new blank line below the command.

graphics/14inf04.jpg

    [ Team LiB ] Previous Section Next Section