Macro is a tool for automating tasks and improves the performance of forms, reports and controls.
Practical tips of Rajab Macros
- Macros in Access are different from macros in Word or Excel. In fact, in Word and Excel, you record the steps on a series of keys and then execute it.
- Access macros are made up of defined operations that allow you to automate repetitive tasks and increase the capabilities of objects and controls.
- Macros can be independent objects that can be seen from the Navigation pane or embedded directly in a Form or Report. After creating database objects such as tables, forms and reports, you can quickly and easily link all objects together with macros and create a simple database program that anyone with even a little knowledge can use. Or change it.
- Macros are a way to execute commands without having to write or even know VBA code, and of course there are many things that can only be achieved with macros.
Build a macro
We want to create a simple macro that creates a form by clicking the command button. To do this, we start with a database and a form called frmEmployeeData, in which there are two tabs.
In the form we add a button that allows the user to open the information of all jobs.
Go to the Design tab of the form and add a button to the form from the controls menu.
The Command Button Wizard box opens. There are several ways to build macro operations, but the easiest way is to easily use the Commander Button Wizard.
For common tasks such as opening a form, select Form Operations from the Categories list and Open Form from the Actions list, and click Next as shown below.
We need to specify which form to open with this button.
Select the frmJobs option here and click Next.
On this page, we have two options: The first option is to open the form and find a specific record, and in the second option, the form opens by displaying all the recorded records. Select the second option and click Next.
We can put an image for the command button or write a custom text. Here we type the View Jobs text to display on the command button and click Next.
As you can see in the image below, we can specify a meaningful name for the command button. With this name we can use the button in other codes or macros. Here I write the name cmdViewJobs and finally click on the Finish button.
Now we go to the form view window.
As you can see, the View Jobs button has been added to the form. Click on it.
A form opens but there is no information in it.
Return to the frmEmployeeData form design section. Select the command button and then go to the Event tab in the Properties Sheet panel on the right.
We see that we created a macro with the wizard embedded in the On Click event. If we want to change the macro, we click on the. Button to open the macro.
The macro design page opens and can be seen on the right side of the Action Catalog panel. Here all operations in the internal folders are specified in the Actions section. Data Entry, Data Import / Export and. Options are seen. On the left is the main part of a macro. This macro contains only one operation and by clicking on the operation you can see the rest of its properties.
In the Form Name field,
the name of the relating form is written, to see other forms in the database, we can click on its arrow. The way the form is displaying is customizable from the View section and we can open it in Form, Design, Print views.
In the Where Condition section, a filter or a condition can be set for Where.
We change the value of the Data Mode field because the frmJobs form is set to Add, which only allows new records to be add. We can define it again in macro by changing it to Edit.
Now we save our macro. Close the macro design window and return to the form design page.
Click the View Jobs button again.
Clicking this button opens the frmJobs form and we can see all the jobs in the database.