I have an unbound data entry form that has two buttons on it. The first automatically saves the data and then closes the form. The second should close the form, and I rely on the form's unload event to prompt the user to confirm that they want to close the form without saving any changes. I keep track of whether any changes have been made with a boolean called Changed.
If the user makes changes and closes the form, then decides to cancel that and go back, they get a "property not found" error. If the user closes the form using the X, they do not get such a method. Can anyone explain what is actually causing this error and how to work around it?
The close button code is simply this:
And this is the unload event:
If the user makes changes and closes the form, then decides to cancel that and go back, they get a "property not found" error. If the user closes the form using the X, they do not get such a method. Can anyone explain what is actually causing this error and how to work around it?
The close button code is simply this:
Code:
Private Sub btnClose_Click() DoCmd.Close acForm, "frmDataEntry" End Sub
Code:
Private Sub Form_Unload(Cancel As Integer)
If Changed Then
rVal = MsgBox("Data has been changed. Do you want to discard changes?", vbYesNoCancel, "Close confirmation")
Select Case rVal
Case vbCancel:
Cancel = True
Case vbNo:
SaveChanges
End Select
End If
End Sub
Comment