Scenario: I have an exit button named cmdClose in the upper right corner of all my forms. I don’t have a separate save and undo button for all of my forms; I just knew that if I can exit from the form without violating any of my validation rule then that means it’s all good and the form is automatically saved after closing it.
I put all of my validation rules on the before update event of all of my forms and it all works terrific at the moment with only one flaw (The form closes after the user had clicked the close button even though the before update event had already kicked in.). See my example code:
What I want is that after the before update event had kicked in, I want to prevent the form from closing even though the client had already clicked the cmdClose button. Instead of closing, I want to redirect the focus to the particular field so that the user will know which is the offended field.
Any suggestions and opinions are welcome. Hopefully, it's a simple but very effective solution. Thank you very much.
I put all of my validation rules on the before update event of all of my forms and it all works terrific at the moment with only one flaw (The form closes after the user had clicked the close button even though the before update event had already kicked in.). See my example code:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.ClientID) Then
MsgBox "Name is empty."
Me.Undo
Cancel = True
Me.ClientID.SetFocus
Exit Sub
ElseIf IsNull(Me.TransactionNameID) Then
MsgBox "No transaction name."
Me.Undo
Cancel = True
Me.TransactionNameID.SetFocus
Exit Sub
ElseIf IsNull(Me.DateTransacted) Then
MsgBox "No transaction date."
Me.Undo
Cancel = True
Me.DateTransacted.SetFocus
Exit Sub
End If
End Sub
What I want is that after the before update event had kicked in, I want to prevent the form from closing even though the client had already clicked the cmdClose button. Instead of closing, I want to redirect the focus to the particular field so that the user will know which is the offended field.
Any suggestions and opinions are welcome. Hopefully, it's a simple but very effective solution. Thank you very much.