Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Using a Before Change macro to create a time stamp

From: Access 2010 Power Shortcuts

Video: Using a Before Change macro to create a time stamp

A Before Change Data Macro allows you to perform an action upon adding, updating, or deleting a record. For example, it's a good idea to have date and time modified fields in your database, so that you know when changes were made to your significant data. For example, open up the Products table. Here is a list of all the products we sell along with their prices and costs. If we update either our retail Price or our wholesale Cost, it would be very useful to have a historic record of the last time any change was made to each product.

Using a Before Change macro to create a time stamp

A Before Change Data Macro allows you to perform an action upon adding, updating, or deleting a record. For example, it's a good idea to have date and time modified fields in your database, so that you know when changes were made to your significant data. For example, open up the Products table. Here is a list of all the products we sell along with their prices and costs. If we update either our retail Price or our wholesale Cost, it would be very useful to have a historic record of the last time any change was made to each product.

To do that, let's go into the Design View, and add the fields we need. I'll right-click on the Products tab, and choose Design View off the shortcut menu. We'll start by adding our date modified field. I'll type in DateModified. Tab to the Data Type, type in a D, which will auto fill Date and Time. Then I'm going to come down to the Format row down in the Field Properties, and change that to Short Date. The next field that I'll create is called TimeModified. It will also be a Date and Time Data Type, and the Format will be Short Time, which will give me military time for the change that I'm making.

Now we're going to add our Before Change Data Macro to our table. A Data Macro is specifically tied to the table itself. So while we are in table Design View, there is a Create Data Macros button and I can choose Before Change. There is another place where I could do this as well. I'm going to switch my view back to the Datasheet View. When it asked if I want to save the table, I'll definitely say Yes. When I go up to the Table tools Ribbon and choose the Table tab, there is a Before Change event on the left-hand side.

Now I am in my Data Macro. There is a dropdown here for me to choose my fields, and I'll choose SetField. The Name of the field that I want to set is DateModified. Notice as I start typing, it auto fills, and all I have to do is press Tab. The Value that I want is going to be Now with an Open and Close parentheses. Next, I need to enter my TimeModified. I could create another SetField step. But an alternative is to Ctrl+Click, and drag the step that I created already.

Notice now my cursor has a Plus sign. It's now duplicated my macro step for me, and I can change the word Date to Time. Now be careful, not to click on the auto fill here, because otherwise you'll get TimeModifiedModified. We'll go ahead and close the macro. When it asked to save it, definitely say Yes. So now I have a Data Macro that before I make a change to the record, it will update these fields. Let's test it out. I'll change the Cost of my first oil to $3.40.

When I Tab passed it, and go to the next record, it automatically fills in for me, the DateModified and the TimeModified. Now here is something to think about. It's good database design. Not to do data entry in tables, but in forms instead, and this is a perfect example why. I have to Tab passed these fields, and even though I have them set to auto fill, I run the risk of thinking that I need to enter it in myself, which increases the possibility of inappropriate data. If I work on the same data from inside of form, I can set it to skip over these fields completely as I tab through my data.

To show you what I mean. Scroll down in the Navigation pane to the Products Split Form and open it up. This form has one product above, and all the products listed below. The first thing that I need to do is modify it to include our new fields. So I'll right- click on the Tab, and change it to Layout View. Go up to the Ribbon on the right-hand side, and click Add Existing Fields. I'll look on my Products table, Find DateModified, and drag it down below Profit. I'll scroll down a little bit.

Drag TimeModified down below DateModified. Now I notice that these two fields are cut-off. So I'll click on one of them on the left-hand side, hold my cursor over the right-hand edge, and drag it. So it's a little bit bigger. Now go up to the right-hand side of your Ribbon and choose Property Sheet. Click on the Date field, and Shift+Click on the Time field. Go over to the Other tab, and change the Tab Stop to No. That way, when I tab through my field, it'll go right from Profit to the next record, and skip Date and TimeModified altogether.

We'll see that in a demonstration after the next steps. Now there is one more consideration. The Before update Data Macro we created was tied specifically to the Products table. To update time and date fields in all of our tables and forms, we'd have to re-create the macro in every single object. Instead, we could make it a stand- alone macro that does the exact same thing. So a huge benefit of doing the macro as a stand-alone Date/Time macro is that we can reuse it to update the date and time of every change in any form or object in the whole database.

So to re-create the macro as a stand- alone, go up to the Create Ribbon and to Macro on the far right-hand side. Now because we're working in a stand-alone macro, when I scroll down, SetValue is not on my list. I have to go up to the Ribbon and choose Show All Actions in order to get the command that I want. I'll go back down, and there is SetValue. I'll click on it. Our Item is going to be DateModified, and our Expression just as before is going to be Now with an Open and a Close parenthesis.

Like before, I can Ctrl+Drag, Copy the macro step, and change the word Date to the word Time. By doing it this way, I can create DateModified and TimeModified fields in every single one of my tables, and then call on this macro, and it will always update that field in that particular table. I'll close my macro, and it'll ask to save it. I'll give it the Name DateTimeStamp. Now back in my form, I'll go back to my Property Sheet, and click on the Events tab, and here I have an option for our Before Update macro.

I'll choose DateTimeStamp. This is the step that you can use in any form to call on the timestamp action. Let's test it out. Go back to your Form View. I'll click on the next product Alberquina 16, and I'll make a change to it. I'll change my Price to $8.35. Now when I tab for my Profit, it jumps straight to the next record. It skips over my DateModified fields. But as you can see below, it filled it in for me.

Using Before Update either as a Data Macro or as a stand-alone Macro will allow you to track when changes are made to your data. This brings a whole new level of data management to your database.

Show transcript

This video is part of

Image for Access 2010 Power Shortcuts
Access 2010 Power Shortcuts

93 video lessons · 7608 viewers

Alicia Katz Pollock
Author

 
Expand all | Collapse all
  1. 1m 15s
    1. Welcome
      47s
    2. Using the exercise files
      28s
  2. 25m 49s
    1. Customizing the Navigation pane
      2m 23s
    2. Toggling between Design and Data views
      2m 40s
    3. Creating new fields with field templates
      2m 9s
    4. Understanding the "Cannot contain a Null value" error
      1m 29s
    5. Working with AutoNumbers as foreign keys
      2m 24s
    6. Using input masks
      2m 39s
    7. Four ways to add fields to a query
      1m 41s
    8. Four ways to filter data
      2m 56s
    9. Selecting multiple form and report controls
      2m 13s
    10. Aligning and distributing controls on forms and reports
      5m 15s
  3. 5m 48s
    1. Opening recent files
      2m 33s
    2. Opening your most recently used file automatically
      56s
    3. Selecting a startup form
      1m 0s
    4. Changing the default saving location
      1m 19s
  4. 8m 22s
    1. Expanding and collapsing the Ribbon
      1m 13s
    2. Three ways to customize the Quick Access toolbar
      3m 14s
    3. Selecting Ribbon buttons using KeyTips
      1m 47s
    4. Creating your own ribbons
      2m 8s
  5. 9m 26s
    1. Turning the Navigation pane into a switchboard
      3m 48s
    2. Right-clicking
      2m 48s
    3. Using keyboard shortcuts
      2m 50s
  6. 5m 56s
    1. Navigating between records
      2m 8s
    2. Using Search, Go to, and Find
      2m 20s
    3. Selecting fields, rows, columns, and tables
      1m 28s
  7. 21m 46s
    1. Undo and Redo tips
      2m 18s
    2. Entering data across, not down
      59s
    3. Repeating data from the record above
      1m 39s
    4. Copying and pasting content
      2m 44s
    5. Inserting today's date
      1m 10s
    6. Removing automatic hyperlinks
      1m 54s
    7. Using AutoCorrect
      1m 36s
    8. Using concatenated fields
      2m 16s
    9. Linking Outlook contacts
      2m 23s
    10. Saving imports and exports for reuse
      4m 47s
  8. 35m 56s
    1. Creating a table using application parts
      2m 18s
    2. Creating Quick Start fields
      1m 49s
    3. Saving application parts
      2m 43s
    4. Understanding number field sizes
      3m 2s
    5. Setting default field types
      2m 55s
    6. Using validation rules
      4m 0s
    7. Using flag fields
      2m 1s
    8. Using an index
      2m 4s
    9. Using a datasheet Totals row
      2m 0s
    10. Filtering by selection
      1m 26s
    11. Resizing columns and rows
      2m 7s
    12. Removing gridlines and shading from tables
      1m 29s
    13. Hiding and unhiding table fields
      1m 13s
    14. Freezing fields when scrolling
      59s
    15. Analyzing your table for redundant structure
      5m 50s
  9. 10m 53s
    1. Setting a starting AutoNumber
      3m 14s
    2. Creating a multi-field primary key
      4m 17s
    3. Using subdatasheets
      1m 27s
    4. Using relationship reports
      1m 55s
  10. 28m 32s
    1. Using wildcards
      5m 40s
    2. Using IN instead of OR
      1m 29s
    3. Hiding query fields
      54s
    4. Changing captions
      1m 31s
    5. Finding duplicate records
      2m 13s
    6. Moving records with append and delete queries
      4m 31s
    7. Using make-table queries
      2m 12s
    8. Creating an update query
      2m 55s
    9. Turning a query into a PivotTable
      2m 30s
    10. Turning a query into a PivotChart
      2m 6s
    11. Using SQL statements
      2m 31s
  11. 28m 48s
    1. Using the property sheet to work with controls
      2m 16s
    2. Creating option groups
      2m 43s
    3. Using a ComboBox to select a record
      2m 55s
    4. Creating tabbed form layouts
      4m 45s
    5. Inserting charts
      3m 42s
    6. Creating your own smart tags
      1m 24s
    7. Using the CanGrow and CanShrink properties
      1m 46s
    8. Hiding fields in printouts
      1m 26s
    9. Setting tab stops
      3m 41s
    10. Clipping, stretching, and zooming images
      1m 17s
    11. Viewing single or continuous forms
      1m 1s
    12. Changing a form's default view
      1m 52s
  12. 9m 7s
    1. Inserting page breaks in reports and forms
      2m 15s
    2. Creating headers and footers
      5m 49s
    3. Hiding duplicates in reports
      1m 3s
  13. 10m 17s
    1. Using themes to customize the look of the database
      4m 12s
    2. Using the Format Painter
      2m 25s
    3. Grouping controls on forms and reports
      1m 35s
    4. Setting default appearance for new databases
      2m 5s
  14. 17m 56s
    1. Using a Before Change macro to create a time stamp
      6m 51s
    2. Triggering a Before Delete warning message
      2m 49s
    3. Creating an After Update macro to email a customer
      2m 11s
    4. Creating a user interface macro
      4m 12s
    5. Using AutoExec macros
      1m 53s
  15. 2m 53s
    1. Saving templates
      2m 10s
    2. Locking files
      43s
  16. 44s
    1. Goodbye
      44s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Access 2010 Power Shortcuts.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.