In addition to the increased security and ease of use that macros provide, you must use macros to perform the following tasks:

For more information about how to build macros, see the section Understand macros.

VBA considerations

You should use VBA programming instead of macros if you want to do any of the following:

Use the Command Button Wizard to perform common programming tasks

If you are adding a command button to a form, the Command Button Wizard can help you get started with programming. The wizard helps you create a command button that performs a specific task. In an Access (.accdb) file, the wizard creates a macro that is embedded in the OnClick property of the command button. In an .mdb or .adp file, the wizard creates VBA code, because embedded macros are not available in those file formats. In either case, you can then modify or enhance the macro or VBA code to better suit your needs.

  1. In the Navigation Pane, right-click the form to which you want to add the command button, and then click Design View.
  2. On the Design tab, click the down arrow to display the Controls gallery, and then ensure that Use Control Wizards is selected.
  3. On the Design tab, in the Controls gallery, click Button.
  4. In the form design grid, click where you want the command button to be placed.
    The Command Button Wizard starts.
  5. On the first page of the wizard, click each category in the Categories list to see which actions the wizard can program the command button to perform. In the Actions list, select the action that you want, and then click Next.
  6. Click either the Text option or the Picture option, depending on whether you want text or a picture to be displayed on the command button.
  7. Enter a meaningful name for the command button. This is an optional step, and this name is not displayed on the command button. However, it is a good idea to enter a meaningful name so that when you need to refer to the command button later (for example, if you are setting the tab order for controls on your form), it will be much easier to differentiate between the command buttons. If the command button closes the form, for example, you might name it cmdClose or CommandClose.
  8. Click Finish.
    Access places the command button on the form.
  9. If you want to see what the wizard 'programmed' for you, follow these optional steps:
    1. If the property sheet is not already displayed, press F4 to display it.
    2. Click the Event tab in the property sheet.
    3. In the On Click property box, click the Build button .
      Access starts the Macro Builder and displays the macro that the wizard created. You can edit the macro if you want (for more information about how to edit a macro, see the section Understand macros). When you are finished, on the Design tab, in the Close group, click Close to close the Macro Builder. If Access prompts you to save the changes and update the property, click Yes to save the changes or No to reject the changes.
  10. On the Design tab, in the Views group, click View, and then click Form View. Click the new command button to confirm that it works as you expected.

Understand macros

A macro is a tool that enables you to automate tasks and add functionality to your forms, reports, and controls. For example, if you add a command button to a form, you associate the button's OnClick event property to a macro that contains the commands that you want the button to perform each time that it is clicked.

It is helpful to think of Access macros as a simplified programming language in which you create code by building a list of actions to perform. When you build a macro, you select each action from a drop-down list and then fill in the required information for each action. Macros enable you to add functionality to forms, reports, and controls without writing code in a VBA module. Macros provide a subset of the commands that are available in VBA, and most people find it easier to build a macro than to write VBA code.

You create a macro by using the Macro Builder, which is shown in the following illustration.

To display the Macro Builder:

Understand VBA code

Like macros, VBA lets you add automation and other functionality to your Access application. You can extend VBA by using third-party controls, and you can write your own functions and procedures for your own specific needs.

A quick way to get started with VBA programming is to first build an Access macro and then convert it to VBA code. Instructions for doing this are included in the section Convert macros to VBA code. This feature creates a new VBA module that performs the equivalent operations in the macro. It also opens the Visual Basic Editor so that you can start modifying the procedure. When you are working in the Visual Basic Editor, you can click keywords and press F1 to start Access Developer Help and learn more about each keyword. You can then explore Access Developer Help and discover new commands to help you perform the programming tasks that you want.

Convert macros to VBA code

You can use Access to automatically convert macros to VBA modules or class modules. You can convert macros that are attached to a form or report, whether they exist as separate objects or as embedded macros. You can also convert global macros that are not attached to a specific form or report.

Note: You can add Visual Basic for Applications (VBA) code to a Web database; however, you cannot run that code while the database is running in a Web browser. If your Web database contains VBA code, you must first open the Web database by using Access before you can run the code. To perform programming tasks in a Web database, use Access macros instead.

Convert macros that are attached to a form or report

This process converts to VBA any macros that are referred to by (or embedded in) a form or report (or any of its controls) and adds the VBA code to the form or report's class module. The class module becomes part of the form or report and moves with the form or report if it is moved or copied.

  1. In the Navigation Pane, right-click the form or report, and then click Design view.
  2. On the Design tab, in the Tools group, click either Convert Form's Macros To Visual Basic or Convert Report's Macros To Visual Basic.
  3. In the Convert form macros or Convert report macros dialog box, select whether you want Access to add error handling code to the functions it generates. Also, if you have any comments in your macros, select whether you want to have them included as comments in the functions. Click Convert to continue.
    If no class module exists for the form or report, Access creates one and adds a procedure to the module for each macro that was associated with the form or report. Access also changes the event properties of the form or report so that they run the new VBA procedures instead of the macros.
  4. To view and edit the VBA code:
    1. While the form or report is still open in Design view, if the property sheet is not already displayed, press F4 to display it.
    2. On the Event tab of the property sheet, click in any property box that displays [Event Procedure], and then click the build button . To view the event properties for a specific control, click the control to select it. To view the event properties for the entire form or report, select Form or Report from the drop-down list at the top of the property sheet.
      Access opens the Visual Basic Editor and displays the event procedure in its class module. You can scroll up or down to view any other procedures that are in the same class module.

Microsoft Access Manual Pdf

Convert global macros

Microsoft Access 2007 Bangla Tutorial Pdf Free Download

  1. In the Navigation Pane, right-click the macro that you want to convert, and then click Design View.
  2. On the Design tab, in the Tools group, click Convert Macros To Visual Basic.
  3. In the Convert Macro dialog box, select the options that you want, and then click Convert.
    Access converts the macro and opens the Visual Basic Editor.
  4. To view and edit the VBA code:
    1. In the Visual Basic Editor, if the Project Explorer pane is not displayed, on the View menu, click Project Explorer.
    2. Expand the tree under the name of the database in which you are working.
    3. Under Modules, double-click the module Converted Macro- macro name.
      The Visual Basic Editor opens the module.

Attach a VBA function to an event property

Free Microsoft Access 2007 Tutorial Pdf

When you convert a global macro to VBA, the VBA code is placed in a standard module. Unlike a class module, a standard module is not part of a form or report. You will most likely want to associate the function with an event property on a form, report, or control so that the code runs exactly when and where you want. To do this, either you can copy the VBA code into a class module and then associate it with an event property, or you can make a special call from the event property to the standard module by using the following procedure.

Instructions

Microsoft Office Access 2007 Tutorial Pdf Free Download

  1. In the Visual Basic Editor, make a note of the function name. For example, if you converted a macro named MyMacro, the function name will be MyMacro().
  2. Close the Visual Basic Editor.
  3. In the Navigation Pane, right-click the form or report with which you want to associate the function, and then click Design View.
  4. Click the control or section with which you want to associate the function.
    Xbox original games list. The game is part of the compliation Grand Theft Auto: The Trilogy which is included on the list.
  5. If the property sheet is not already displayed, press F4 to display it.
  6. On the Event tab of the property sheet, click the event property box with which you want to associate the function.
  7. In the property box, type an equal sign (=) followed by the name of the function — for example, =MyMacro(). Be sure to include the parentheses.
  8. Save the form or report by clicking Save on the Quick Access Toolbar.
  9. In the Navigation Pane, double-click the form or report, and test it to see that the code runs as it should.

Access 2007 Training Manual

You now know the basic steps to add VBA code to your database. This article describes only the basics of how to get started; there are many excellent reference books and online resources that can help you build your programming skills.