I have the following code set to a save button
Code:
Private Sub cmd_save_Click()Dim ctrl As Control
str = Empty
For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
If IsNullorEmpty(ctrl) Then
ctrl.BackColor = RGB(119, 192, 212)
ctrl.BorderColor = RGB(157, 187, 97)
str = str & ctrl.Tag & vbNewLine
Else
ctrl.BackColor = vbWhite
ctrl.BorderColor = RGB(192, 192, 192)
End If
End If
Next ctrl
If IsNull(str) Or str = "" Then
DoCmd.OpenForm "frm_Josh"
Exit Sub
Else
MsgBox "Please enter data for all the required fields below." & vbNewLine & _
String(52, "-") & vbCrLf & str, vbInformation + vbOKOnly, "Fill in Blanks"
Exit Sub
End If
End Sub
This prevents any text boxes from being left empty. However anyone can just close the form without having to click the save button. I don't have a close button enabled, they can simply click on another tab to get out of the form. I was hoping I can add a me.dirty function or something that directs them to have to click the save button and then if all boxes are filled they can navigate away from this form.
Thanks in advance.