Question on command button Exit code
Posted on 2007-10-02
I have a small snag in my command Exit code.
If a user enters data, clicks exit and chooses to save the data, BUT a mandatory field isn't completed, the form just exits without saving. In this case I will do better to cancel the exit and flag up the mandatory fields.
In addition, because the mandatory field isn't completed, record should not save until the mandatory field is completed. This way focus will remain on the mandatory function.
My current Mandatoryfields function works. However, In order to avoid pasting too many code on this post, the MandatoryFields Function can be found at the link below:
I will appreciate assistance in editing this code to perform better and expected.
Here is my current code:
Private Sub btnExit_Click()
On Error GoTo ErrRtn
Dim txStr As String
If Me.Dirty Then
txStr = "Do you want to save the new data?"
Select Case MsgBox(txStr & vbCrLf & _
"(Cancel to return to the form.)", vbYesNoCancel)
If Not MandatoryFields Then ' < ----- Checks for missing fields