4.5. Creating a Procedure for Access

Access has a long tradition of independence from the other Office applications, and this applies as well to its implementation of macros. For one thing, it has no recorder, nor does it permit you to assign macros to shortcut key combinations. In addition, it includes a "Macro Builder," which you can take a look at by clicking the Macro button on the Create tab of the Ribbon. (Note that in Access there is no Developer tab on the Ribbon. You can open the Visual Basic Editor from the Database Tools tab, or press Alt+F11.)

The Macro Builder has been generally unpopular over the years because the Visual Basic Editor offers more options, objects, and features. However, the Builder is improved in Access 2007, including provisions for error handling and the ability to embed macros within individual forms. Nonetheless, you will likely prefer to use the Visual Basic Editor rather than the Builder for any but the simplest macros.

In this example, you'll write a macro that displays today's date and time:

  1. Start Access.

  2. Click the Blank Database button, then click the Create button.

  3. Press Alt+F11 to open the Visual Basic Editor.

  4. Right-click the database name in the Project Explorer, then choose Insert Module to open a new module in the Code window where you can write macros.

  5. In the Code window, type the following macro:

    Sub ShowDate()
    
    MsgBox ("It is: " & Now)
    
    End Sub

  6. Click anywhere within this code, and then press F5 to execute the macro. You should see a message box that displays the current date and time.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.65.1