Topic: Macros, Modules, Data Access Pages and Internet
Topic: Macros, Modules, Data Access Pages and Internet
Macros: How to Create and Run Modules Macros vs Modules Jumping to Internet
Create a macro
1 2 3 4 5 6
1
In the Database window, click the Macros tab. Click New. In the Action column, click in the first cell and then click the arrow to display the action list. Click the action you want to use. Type a comment for the action. Comments are optional, but make your macro easier to understand and maintain. 2 In the lower part of the window, specify arguments for the action, if any are required.
conditional expression An expression that Microsoft Access evaluates and compares to a specific value for example, If...Then and Select Case statements. If the condition is met, one or more operations are carried out. If the condition isn't met, Microsoft Access skips the operations associated with the expression and moves to the next expression. You can use conditional expressions in macros and Visual Basic code. argument A constant, variable, or expression that supplies information to an action, event, method, property, or procedure.
2
To add more actions to the macro, move to another action row, and repeat steps 3 through 6. Microsoft Access carries out the actions in the order you list them.
3
Tip To quickly create a macro that carries out an action on a specific database object , drag the object from the Database window to an action row in the Macro window. For example, you can create a macro that opens a form by dragging the form to an action row. To do this, click Tile Vertically on the Windows menu to position the Macro window and Database window so that they're both visible on your screen; then click the tab in the Database window for the type of object you want to drag, click the object, and drag it to an action row. Dragging a macro adds an action that runs the macro, while dragging other objects (tables, queries, forms, reports, or modules) adds an action that opens the object.
Run a macro
When you run a macro, Microsoft Access starts at the beginning of the macro and carries out all the actions in the macro until it reaches either another macro (if the macro is in a macro group) or the end of the macro. 4 You can run a macro directly, from another macro or an event procedure , or in response to an 5 event that occurs on a form, report, or control. For example, you can attach a macro to a command button on a form so that the macro runs when a user clicks the button. You can also create a custom menu command or toolbar button that runs a macro, assign a macro to a key combination, or run a macro automatically when you open a database.
In the toolbox, click the Command Button tool . On the form, click where you want to place the command button. Make sure the command button is selected, and then click Properties on the toolbar to open its property sheet. In the OnClick property box, enter the name of the macro or event procedure that you want to run when the button is clicked, or click the Build button to use the Macro Builder or Code Builder. If you want to display text on the command button, type the text in the Caption property box. If you don't want text on the button, you can use a picture instead.
database objects Tables, queries, forms, reports, macros, and modules. event procedure A procedure automatically executed in response to an event initiated by the user or program code, or triggered by the system.
5 4
event An action recognized by an object, such as a mouse click or key press, for which you can define a response. An event can be caused by a user action or a Visual Basic statement, or it can be triggered by the system. Using properties associated with events, you can tell Microsoft Access to run a macro, call a Visual Basic function, or run an event procedure in response to an event.
class module A module that can contain the definition for a new object. When you create a new instance of a class, you create the new object. Any procedures defined in the module become the properties and methods of the object. Class modules in Microsoft Access exist both independently and in association with forms and reports.
7
standard module A module in which you can place Sub and Function procedures that you want to be available to other procedures throughout your database. Function procedure A procedure that returns a value and that can be used in an expression. You declare a function with the Function statement and end it with the End Function statement.
9 8
Sub procedure A procedure that carries out an operation. Unlike a Function procedure, a Sub procedure doesn't return a value. You declare a Sub procedure with the Sub keyword and end it with an End Sub statement.
In Microsoft Access, you can accomplish many tasks with macros or through the user interface. In many other database programs, the same tasks require programming. Whether to use a macro or Visual Basic for Applications often depends on what you want to do.
when the macro is running. With Visual Basic, however, you can pass arguments to your code at the time it is run or you can use variables for arguments something you can't do in macros. This gives you a great deal of flexibility in how your Visual Basic procedures run.