Ready to watch this entire course?
Become a member and get unlimited access to the entire skills library of over 4,900 courses, including more Business and personalized recommendations.Start Your Free Trial Now
- View Offline
- Working with Application Parts
- Implementing the Table Tools ribbon
- Using Quick Start and calculated fields
- Designing with Layout View formatting tools
- Taking advantage of enhancements to the Conditional Formatting feature
- Automating with macros
- Working with external data
- Integrating SharePoint publishing
Skill Level Intermediate
Access 2010 has a new macro technique called data Mmacros, which can trigger by your data instead of your database objects. You can now add logic macros directly to your tables and any dependent objects will inherit the macro. The macro is stored in the table instead of in the dependent objects. This means, for example, that the action will get triggered automatically when you're looking at a form or running a report instead of having to be reprogrammed every time. This allows you to take actions based on the data in your table. Some examples include an inventory database, adding records to an order table if an items quantity falls below a certain level.
Sending thank you e- mails based on orders placed. Popping up warnings if all required fields are not completed. So, let's go take a look and see how this works. We are going to open up our Employees table. What we are going to do is the employees that go into this table either are in the Purchasing department or the Marketing department. Any time we put in the Purchasing department we want the Salary to automatically fill in this $15 an hour. If we type in Marketing we want the Salary to automatically put in $17 an hour.
By not having to entering the salary by hand, we both eliminate redundant data entry and reduce errors. So, let's see how this works. We'll come up here to the Table tab and we'll click on After Update. Now, these were available in Access 2007 but they were in the Properties. I'll click on After Update and it will open up the macro. The first thing that I am going to do is an If statement because I need to specify that if it's Purchasing its 15 and if it's Marketing it's 17. So, I start by typing in the field that contains the comparison and that's department.
So, if Dept="Purchasing". You do have to use proper syntax. If you're not sure what that proper syntax is, please see our Access 2010 Essential Training course. So, our department is purchasing and then we have to tell it to EditRecord. We can skip the Alias and we need to tell it to set the fields Salary to 15. Now, click back on the macro and we'll Add Else If.
This time if our Dept="Marketing" then we'll EditRecord and set the field Salary to 17. We'll save the macro, close it, and come back to our table to give it a try. So, the Department is Purchasing and I am going to skip right over Salary. When I go down to the next record it automatically fills it in. When I enter a new record, again I'll skip the field and there is our $17.
These new data macros add power to your database, allowing it to manage tasks based on the records in your tables.