Macros
Home FAQ Getting Started Tables Queries Forms Reports Macros/VBA

 

Macros
VBA Code
Neat VBA

Step Number 1

Now, we are going to go through the process of creating a simple macro. First, make sure that your database window is open and that Macros is selected. Click on the New button.

Figure 1 - Click here to view a larger version of the image.

Step Number 2

The macro design window should appear. It will look like the one below. A macro is a sequence of actions that are stored so that they can be performed again and again.

Figure 2 - Click here to view a larger version of the image.

Step Number 3

In the first line of the Macro Editor window, select RunCommand from the drop down list. In the list box at the bottom, select Exit. This simple macro will now allow you to exit from Microsoft Access.

Figure 3 - Click here to view a larger version of the image.

Step Number 4

Next, go to the File menu and select Save As.

Figure 4 - Click here to view a larger version of the image.

Step Number 5

Now, exit the Macro editor and open the Main Switchboard form in design view.

Figure 5 - Click here to view a larger version of the image.

Step Number 6

You should see the screen below. Go ahead and place a label on the form and set its caption to Exit Program.

Figure 6 - Click here to view a larger version of the image.

Step Number 7

Now we will Add a command button to the form. This button will run our macro for us. The command button wizard should appear once you have added the button to the form. In the left hand list box, select Miscellaneous and then select Run Macro from the list on the right. Then click Next.

Figure 7 - Click here to view a larger version of the image.

Step Number 8

Next, select macEnd from the list of Macros in this step (since it's the only one, it is a rather obvious choice). Click Next

Figure 8 - Click here to view a larger version of the image.

Step Number 9

Now, we need to select a picture from the list. I picked the picture titled Exit, but you may choose another if you have one that is more appropriate. After you are finished choosing a picture, click Next to continue.

Figure 9 - Click here to view a larger version of the image.

Step Number 10

Now, name the command button something meaningful, like cmdExit and click Finish. If you open the switchboard now and click on the exit button, it should completely close Access. See how easy it is to create a macro to automate repetitive actions!

Figure 10 - Click here to view a larger version of the image.