Results 1 to 6 of 6
  1. #1
    bignate is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2013
    Posts
    47

    Question Question Check if any changes have been made to the record

    I use the code below when a form is closed to either save or undo changes. However I only want the msg box to appear if there have been any changes to the record that the form is based on, if there aren't any changes then it will just docmd.close without the msgbox. How would I check if there have been any changes to the record? I think you have to use 'Dirty' but im not really sure how to use it.




    Private Sub CLoseUR_Click()


    Dim strMsg As String, strTitle As String


    strMsg = "Do you want to save changes?"
    strTitle = " Save Changes?"


    If ValidateForm Then
    Else
    If MsgBox(strMsg, vbQuestion + vbYesNo, strTitle) = vbNo Then
    Me.Undo
    DoCmd.Close
    Else
    DoCmd.Close
    End If
    End If
    End Sub

  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,521
    If Me.Dirty Then
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    IMHO it would be better to have validation code in the form's Before Update event.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    bignate is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2013
    Posts
    47
    I just got Me.Dirty to work, thanks guys.
    Bob Fitz are you suggesting I use Me.Dirty in the BeforeUpdate?

  5. #5
    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
    No, he's suggesting that you put your code asking the user if he wants to save the changes in the Form_BeforeUpdate event. Doing this, there is no need to 'check' whether the Form is Dirty or not. The Form_BeforeUpdate event only fires if the Form has been Dirtied!

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

    All posts/responses based on Access 2003/2007

  6. #6
    bignate is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2013
    Posts
    47
    Oh okay thanks, if I do it this way would it think there is an update if a user adds a space and removes it again using backspace.

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

Similar Threads

  1. Replies: 7
    Last Post: 02-26-2013, 10:37 AM
  2. Track employee who made changes to record.
    By FormerJarHead in forum Access
    Replies: 4
    Last Post: 01-09-2013, 04:40 PM
  3. Check if record exists, Check Number
    By burrina in forum Forms
    Replies: 9
    Last Post: 01-06-2013, 03:49 PM
  4. Replies: 3
    Last Post: 10-19-2012, 04:30 PM
  5. Replies: 1
    Last Post: 03-28-2012, 03:27 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