Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

MS Access macro


May 17, 2021 MS Access


Table of contents


In this chapter, we'll visit the basics of macros. M acros are a tool that lets you automate tasks and add features to your forms, reports, and controls.

  • Macros in Access are a little different from those in Word or Excel, where you basically record a series of quiet and try them later.

  • Access macros are built from a predefined set of actions that allow you to automate common tasks and add functionality to controls or objects.

  • Macros can be separate objects that can be viewed from the navigation pane, or they can be embedded directly in a form or report. b20> or even modify with relatively little training.

  • Macros provide a way to run commands without having to write or even know VBA code, and there are many that you can implement just with macros.

Create a macro

Let's start by creating a very simple macro that opens the form when we click the command button. To do this, we need to open your database and the frmEmployeeData form, where we have created two tabs.

MS Access macro

In this form, we can add a button that allows the user to open all the work information.

MS Access macro

Now let's go to the design view of this form and add a button to the control menu. When you release the mouse, you'll see the Command Button Wizard dialog box

MS Access macro

There are several ways to build macro operations, but the easiest way is to simply use the command button wizard.

MS Access macro

For common actions, such as opening a form, select the form action from the list of categories, and then select the open form from the list of actions, as shown in the screenshot above, click Next.

MS Access macro

You need to specify the form to open using the command button. Now, let's select frmJobs and click Next.

MS Access macro

On this screen we have two options, we can open the form and display a very specific record, or we can open the form and display all the records. Let's select the second option and click the next screenshot like the one above.

MS Access macro

We can make the command button itself display the picture, or you can choose to display the text. Here we want to display the text to view the job, now click Next.

MS Access macro

You can now give the command button a meaningful name, as in the screenshot above. T his can be used in other code or other macros. Let's call this cmdViewJobs and click Done.

Now go to the form view.

MS Access macro

You can now see the View Task button on the form. Let's click on it.

MS Access macro

Now you have a form open, but you won't view any information. L et's go back to the frmEmployeeData form design view. Make sure that the command button is selected, and then click the event tab on the property sheet.

MS Access macro

Once clicked, you'll see embedded macros created by the wizard. I f you want to modify this macro now, click... button to open the macro generated by the wizard

MS Access macro

This is the macro designer, on the right, you will see the action directory. T his is where all operations will be stored in the folder. b20> on.

MS Access macro

You'll see the form name, and you can click the down arrow to see the forms available in the database. b20> de. ere we're going to change the data mode because the frmJobs are set to add mode, allowing only new records to be added. W e can override this macro in this macro by changing it to edit mode.

MS Access macro

Now save the macro, then close the macro designer and return to the form view.

MS Access macro

Let's click again to see the task.

MS Access macro

You can now see it open your frmJobs form and allow you to scroll through all the available tasks in our database.