| Macros in Access can be considered like a simplified programming language that can be used to increase the functionality of the data base. For example, it can enclose a macro to a command button in a form, so the macro is executed when clicking in the button. The macros contain actions that make tasks, like opening a report, executing a query or to close the data base. Almost all the operations of data bases that normally are made manually can automate by means of macros, thus saving time. |
| Modules, like macros, are objects that serve to increase the functionality of the data base. Whereas the macros in Access are created selecting actions of a list, the modules are written in the Visual BASIC programming language for Applications (VBA), a version of the language of macros of Visual Microsoft BASIC who is used to program applications based on Microsoft Windows and who is included in several programs of Microsoft. A module is a collection of declarations, instructions and procedures that are stored jointly like a unit. There are two kinds of modules: standard modules and class modules. The class modules are joined to forms or reports, and normally they contain specific procedures of the form or the report to which they are enclosed. The standard modules contain general procedures that are not associated to any other object. |
| Macros |
| 1) In the Create tab, in the group Other, click in Macro command, then Macro menu item. |
|
| Illustration 1: Select the Macro command. Click here to view larger image. |
| 2) The Macro definition panel will appears. |
|
| Illustration 2: You will configure the macro in this panel. Click here to view larger image. |
| 3) Select the OpenForm action. |
| 4) Configure the OpenForm arguments. |
|
| Illustration 3: You will configure the macro in this panel. Click here to view larger image. |
| 5) A condition specifies certain criteria that must be met before an action will be performed. You can use any expression to evaluate to true or false or Yes or No the expression and execute or not some commands based in these results. |
|
| Illustration 4: Configure all action Arguments. Click here to view larger image. |
| 6) Once configured the action and its arguments, save the macro. |
|
| Illustration 5: Save the macro by closing it. |
| 7) Open a Blank Form in Design View. |
| 8) Expand the Form Footer area. |
| 9) Select the Command Button control from the Controls Tab. |
|
| Illustration 6: Select the button control. Click here to view larger image. |
| 10) Draw the button at the Form Footer area. |
| 11) Select the Miscellaneous and Run macro Options from the emerging menu. Press the NEXT button. |
|
| Illustration 7: Select the Run Macro Action. |
| 12) Select the previously saved macro. Press the NEXT button. |
|
| Illustration 8: Select the recently saved macro. |
| 13) Assign a text or an image to the button. Press the NEXT button. |
|
| Illustration 9: You could configure graphical or textual buttons. |
| 14) Assign a name to the button control. Press the FINISH button. |
|
| Illustration 10: Give a descriptive name to your control. |
| 15) Save the form and test it. |
|
| Illustration 11: Save and test. Click here to view larger image. |
|
| Illustration 12: The macro is fully working. Click here to view larger image. |
| Modules |
| 16) Open a Blank Form in Design View. |
| 17) Select the Command Button control from the Controls Tab. |
| 18) Draw the button at the Form Footer area. |
| 19) Press the CANCEL button to exit the control configuration wizard. |
| 20) Double click on the command button to open the properties sheet. |
| 21) Select the Event tab. |
|
| Illustration 13: The macro is fully working. Click here to view larger image. |
| 22) Click on the Macro list to show available macros. |
|
| Illustration 14: Another way to assign a macro to a button. |
| 23) Click on the ¡ button to open the wizard. |
| 24) Select the Code Builder option and press the OK button. |
|
| Illustration 15: Builder options. |
| 25) Select the Code Builder option and press the OK button. The Visual Basic code editor will appear. |
|
| Illustration 16: Code builder ready to write VBA code for the Command4 button. Click here to view larger image. |
| 26) Write the sentence and close the VBA Editor. |
|
| Illustration 17: Code to show a message. Click here to view larger image. |
| 27) Run the form and execute the button. |
|
| Illustration 18: The button raises the coded message. Click here to view larger image. |
discuss this topic to forum
