Results 1 to 12 of 12
  1. #1
    CementCarver's Avatar
    CementCarver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    231

    Record Modification Dates

    I have several edits forms that my client will be using to edit existing data. But what I'm looking for is to be able to record the date/time when any record gets changed.

    How can this be achieved with VB? Or is there a simpler solution?



    CementCarver

  2. #2
    dniezby is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2013
    Posts
    183
    The method I use is create a timestamp.

    In the tables that you're using, create a date field. Even better, two date fields.

    One that is called, timestamp and one called modified_rec.

    The timestamp field is easy. In the default value you simply put, Now() and it will put the date and time that the record is entered. For modified, I would say, leave that blank and do some VB code.
    Code:
    Private Sub Form_Dirty()
    
    ' If the record gets edited in anyway, record the date and time.
    modified_rec = Now()
    End Sub

  3. #3
    CementCarver's Avatar
    CementCarver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    231
    Thanks Dniezby. I'll give that a try.

    CementCarver

  4. #4
    dniezby is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2013
    Posts
    183
    Quote Originally Posted by CementCarver View Post
    Thanks Dniezby. I'll give that a try.

    CementCarver
    No problem. I hope it helps. If it doesn't work where I put it in this example, I've found that finding the right trigger event changes everything. For example, if someone changes a field that you KNOW will always be updated, then put the trigger there. Let me know how it turns out.

  5. #5
    CementCarver's Avatar
    CementCarver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    231
    But how do I track whether the record has been changed or not? Do I have to test every field to see if it's been changed?

    CC

  6. #6
    dniezby is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2013
    Posts
    183
    Quote Originally Posted by CementCarver View Post
    But how do I track whether the record has been changed or not? Do I have to test every field to see if it's been changed?

    CC
    The OnDirty Trigger fires as soon as ANYTHING in that record is even touched.

  7. #7
    dniezby is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2013
    Posts
    183
    Also, forgot that you will need to format the subroutine like this:
    Code:
    Private Sub Form_Dirty(Cancel As Integer)
    modified_rec = now()
    End Sub

  8. #8
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Actually, the kind of code needs to be in the Form_BeforeUpdate event. This event will fire if and only if a change has been made to the Record. The user could Dirty the Record, change their mind, and end up not changing any data, but having the code in that event would indicate (wrongly) that the Record was modified! Choosing the proper event is, indeed, critical.

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
     If Not Me.NewRecord Then
       Me.modified_rec = Now()
     End If
    End Sub
    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  9. #9
    dniezby is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2013
    Posts
    183
    Quote Originally Posted by Missinglinq View Post
    Actually, the kind of code needs to be in the Form_BeforeUpdate event. This event will fire if and only if a change has been made to the Record. The user could Dirty the Record, change their mind, and end up not changing any data, but having the code in that event would indicate (wrongly) that the Record was modified! Choosing the proper event is, indeed, critical.

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
     If Not Me.NewRecord Then
       Me.modified_rec = Now()
     End If
    End Sub
    Linq ;0)>
    Also a good place to put it.

  10. #10
    CementCarver's Avatar
    CementCarver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    231
    Thank you.

    CementCarver

  11. #11
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Glad we could help!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  12. #12
    dniezby is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2013
    Posts
    183
    Quote Originally Posted by CementCarver View Post
    Thank you.

    CementCarver
    Pretty neat little technique huh? It's amazing how somethings can be so simple and things that seem simple can be soooo difficult in programming. Damn logic.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Query modification
    By endri81 in forum Queries
    Replies: 28
    Last Post: 02-29-2012, 09:50 AM
  2. Replies: 10
    Last Post: 11-16-2011, 10:58 AM
  3. Update datetime stamp on record modification
    By sitaramnayak in forum Access
    Replies: 1
    Last Post: 10-12-2011, 11:54 AM
  4. Record Retrieval/Modification Based On Entry
    By eddiebo924 in forum Forms
    Replies: 1
    Last Post: 06-19-2011, 06:41 PM
  5. Access total UI modification
    By Overdive in forum Access
    Replies: 5
    Last Post: 10-25-2009, 05:53 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums