Access: Introduction To Macros and SQL: What Is A Macro?
Access: Introduction To Macros and SQL: What Is A Macro?
What is a macro?
A macro is a series of actions programmed to automate repetitive tasks.
Macros in Access
Access provides two categories of macros: stand-alone macros and embedded macros.
A stand-alone macro is a separate database object. A stand-alone macro appears as an object in the
Navigation Pane and it can be run independently. It is also available to any control or object in the
database.
An embedded macro is embedded in an object or a control. With an embedded macro, an event occurs
that is attached to a control or an object and the event triggers the embedded macro. An example of
an event would be the On Click event that occurs when the user clicks on a button or the Before Change
event that is triggered each time a user enters or edits data in a field in a table.
8. Close the macro. Double-click the Open2Reports macro to test that it executes properly. Both
reports should open.
9. Close both the reports.
10. Save the database.
1. Double-click on the Main Menu form in the Navigation Pane. Click the Open Locations Form
button on the Main Menu form. The Locations form should open. Close the Locations form.
2. Click the Exit button on the Main Menu form. This button will close your database and exit
Access.
3. Reopen the accessMacros_Practice database.
4. Click on the Main Menu form and display it in Design View. Click on the Button control in the
DESIGN tab of the FORM DESIGN TOOLS Ribbon.
5. Click and drag to size a button directly below the Open Locations Form button and above the
Exit button.
6. When the Command Button Wizard appears, select Report Operations from Categories and
Open Report from Actions. Click the Next > button.
7. Then select Employee Compensation as the report to open. Click the Next > button.
8. Click the Text radio button and type Open Employee Report as the text to display on the button.
1. Open the Employees table in Datasheet View. Note: the InsuranceDate field for every record is
currently blank.
2. Switch to Design View.
3. Click Create Data Macros in the Field, Record & Table Events group on the Design tab, and then
click the Before Change event.
8. Change the HireDate for Laurie Fantis to 1/11/2013 and navigate to the next record. The
InsuranceDate for Laurie Fantis will now show as 3/12/2013.
9. Save and close your database.
An SQL SELECT Statement is used to retrieve specific data from the database. Keywords in the SELECT
statement have specific meaning and purpose:
1. With the Employees table selected in the Navigation Pane, create a new report.
2. Save this new report as Employees. Scroll to the bottom of the report to note there are 311
records.
3. Display your Employees report in Design View.
4. On the Property Sheet, display the Data Tab.
5. Notice Employees shows in the Record Source. Employees is the name of the table you used to
create this report.
There are 4 job titles in this company (T01, T02, T03, and T04). You are designing this report to only
display employees with the title of “T01”.
6. Make sure your cursor is in the Record Source textbox. Right-click or press Shift+F2 to display
the Zoom window. Type the following SQL SELECT statement in the Zoom window:
SELECT * FROM Employees WHERE Title=”T01”;