Question : me.dirty not getting recognized in form_close

please find my code snippet.

while closing a form,  all the unsaved data is getting saved into the database.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
Private Sub Form_Close()
 
If Me.Dirty = True Then
    Response = MsgBox("Record updated. Do you you want to save changes", vbOKCancel)
End If
    If Response = vbOK Then
        DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    Else
    Me.Undo
    End If
 
End Sub
Open in New Window Select All

Answer : me.dirty not getting recognized in form_close

This is all a little like having a sign by the side of the road - facing the road which reads
"Did you mean to just cross this road - it's quite busy and you possibly didn't want to at this time"

In other words, by the time you're in the Close (or Unload) event you're all done saving that record.
You can issue an explicit save if you must - but it's completely redundant. The save has already implicitly occured before this point.

You can put this sort of checking in a command button to verify the user's choice, but in a form event you'd need to choose an alternative.
Obviously BeforeUpdate is the standard option (which you Cancel if you don't want updates to proceed).
Still not intended as a default usage example - but as a demonstration of the various techniques - there's the Cancel Undo MDB in the examples page linked to in my profile.

Random Solutions  
 
programming4us programming4us