Frank Freese
asked on
close a form with or without saving changes
I would like to be able to advise the user when they close a form and there has been changes on if they want to save the changes or not
Ru looking to let the user know or have a pop up message to give an option to save or not save the changes...is that the question?
ASKER
When a form is closed a pop up message would appear asking them if they want to save the record. If the say no then no record is written
is this a bound form?
Private Sub Form_UnLoad(Cancel As Integer)
If Me.Dirty = True Then
If MsgBox ("Do you want to save the changes?", 20,Me.Caption) = vbYes Then
Me.Dirty = False
End If
End If
End Sub
If Me.Dirty = True Then
If MsgBox ("Do you want to save the changes?", 20,Me.Caption) = vbYes Then
Me.Dirty = False
End If
End If
End Sub
Mod:
Private Sub Form_UnLoad(Cancel As Integer)
If Me.Dirty = True Then
If MsgBox ("Do you want to save the changes?", 20,Me.Caption) = vbYes Then
Me.Dirty = False
Else
Me.Undo ' **** ADD THIS
End If
End If
End Sub
Private Sub Form_UnLoad(Cancel As Integer)
If Me.Dirty = True Then
If MsgBox ("Do you want to save the changes?", 20,Me.Caption) = vbYes Then
Me.Dirty = False
Else
Me.Undo ' **** ADD THIS
End If
End If
End Sub
ASKER
The form is bound. Some of the fields have default values and those controls are locked. The me.dirty=true is false because the user did not actually enter any data themselves.
If not data was entered, what is there to save ?
mx
mx
ASKER
the defaults arew being saved
Defaults are not Saved unless the record is made Dirty by and Edit of some bound field.
mx
mx
ASKER
i stand corrected. however, when I did put data in the form_unload me.dirty came back as false not true and the msgbox was not executed.
fh_freese,
how are your users close the form? do you have command button for this?
how are your users close the form? do you have command button for this?
ASKER
yes.
Docmd.close
Docmd.openform "Main Menu"
Docmd.close
Docmd.openform "Main Menu"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Private Sub btnClose()
If Me.Dirty = True Then
If MsgBox ("Do you want to save the changes?", 20,Me.Caption) = vbYes Then
Me.Dirty = False
Else
Me.Undo ' **** ADD THIS
End If
End If
docmd.Close acForm, me.name
End Sub
Also ... turn off the Close X button on the form property sheet.
ASKER
thanks. hope not to revisit this. much appreciated.