Results 1 to 4 of 4
  1. #1
    dniezby is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2013
    Posts
    183

    Best way to check a form for updates before closeing

    Anyone have code for checking a form for updates (not just dirty) before closing a form?



    Right now I just have this.

    Code:
    Private Sub Form_Close()
    'If the form has modified update the modified date
    
    If Me.Dirty Then
        
        Me.Modified = Now()
        
    Else
        DoCmd.Close
    
    
    End Sub
    The only issue is, what if the person doesn't actually update any of the data? I don't want the modified timestamp to change unless they actually change the physical data.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    I would like expect testing dirty to work. Does it not? The before update event should only fire if they changed something. If you want to make sure they didn't change it back, you could loop the controls and compare the Value and OldValue properties.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    A couple of things:

    The Form_Close event is too late for this...the Record is already saved by the time it executes, and hence is no longer Dirty.

    Having DoCmd.Close in this event is going to pop an error...it's actually going to prevent the Form from closing, which it was already set to do.

    As Paul suggested, you'll need to check, in the Form_BeforeUpdate event, whether any Control has actually been changed, and assign Now() to Modified, if it has.

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

    All posts/responses based on Access 2003/2007

  4. #4
    dniezby is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2013
    Posts
    183
    Quote Originally Posted by Missinglinq View Post
    A couple of things:

    The Form_Close event is too late for this...the Record is already saved by the time it executes, and hence is no longer Dirty.

    Having DoCmd.Close in this event is going to pop an error...it's actually going to prevent the Form from closing, which it was already set to do.

    As Paul suggested, you'll need to check, in the Form_BeforeUpdate event, whether any Control has actually been changed, and assign Now() to Modified, if it has.

    Linq ;0)>
    So it looks like I was doing it right in the first place.

    I already have this in my form's before update
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    Me.Modified = Now()
    End Sub

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

Similar Threads

  1. Replies: 41
    Last Post: 12-06-2016, 08:40 AM
  2. Combobox updates form
    By Voodeux2014 in forum Forms
    Replies: 5
    Last Post: 12-08-2014, 01:22 PM
  3. Replies: 18
    Last Post: 06-20-2014, 12:13 PM
  4. Replies: 6
    Last Post: 11-30-2013, 02:41 PM
  5. Tracking Log of updates in a form
    By cin324 in forum Access
    Replies: 9
    Last Post: 11-30-2011, 01:12 PM

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