Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
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.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 91348 Viewers
80 Video lessons · 138247 Viewers
59 Video lessons · 57078 Viewers
52 Video lessons · 70728 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.