I have a fairly simple form, with a number of field in it including a combo box called "Status" which has two options (Resolved and Active) and a text field called "Resolved Date".
Resolved Date only needs to be filled in when Status = "Resolved".
I also have a cancel button (which allows the user to leave without saving changes) and a close button (which saves all changes and closes the form). The original code for the close button was:
CODE
Private Sub cmdSaveRecord_Click()
On Error GoTo Err_cmdSaveRecord_Click
If Me.Dirty Then Me.Dirty = False
DoCmd.Close
Exit_cmdSaveRecord_Click:
Exit Sub
Err_cmdSaveRecord_Click:
MsgBox Err.Description
Resume Exit_cmdSaveRecord_Click
End Sub
I wanted to put in place validatin rule so that a person could not leave the form after changing the status to resolved without entering a resolved date.
So I put in a Before Update event which looked like:
CODE
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.DateResolved) And Me.Status = "Resolved" Then
MsgBox "You must enter a resolved date"
Cancel = True
End If
End Sub
However when I was testing the validation and clicked the close button when Status = Resolved, but Resolved Date was empty, it would throw an error message "The setting you entered for this property isnt valid".
I googled around a bit and found someone with the same problem. He identified the me.dirty command as causing the issue. So I changed the close button code to:
CODE
Private Sub cmdSaveRecord_Click()
On Error GoTo Err_cmdSaveRecord_Click
If Me.Dirty Then
DoCmd.RunCommand acCmdSaveRecord
End If
DoCmd.Close
Exit_cmdSaveRecord_Click:
Exit Sub
Err_cmdSaveRecord_Click:
MsgBox Err.Description
Resume Exit_cmdSaveRecord_Click
End Sub
Now when I test the validation rule, the error message about not being valid is now hone, but now immediately after the error dialogue box pops up telling me to fill out the resolved date, I get a second dialogue box telling me the Run command was cancelled (as per the instructions cancel = false).
Is there any way I can stop this second dialogue box popping up? I freely admit to muddling through this - its been years since I have used VBA and cant remember much. I was hoping maybe someone had an idea of what I can do.