Generally, you use this for data validation before actually saving the data
into the Table and in this case, I would normally use the Form_BeforeUpdate
Event, i.e. just before the data is updated into the Table.
I have this code in the Form_BeforeUpdate Event. This is the code that
checks the SOCStart Field. I believe this should execute before closing the
form...correct?
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(SOCStart) Then
MsgBox "The SOC Date must be entered", vbOKOnly
SOCStart.SetFocus
Cancel = True
Exit Sub
End If
End Sub
This does not work. The message appears but the form closes anyway. What
am I doing wrong?
I am sure it is simple but I cant find it.
Not sure but try getting rid of the Exit Sub. The code looks OK except the
Exit Sub is not necessary and it may (???) affect the return of Cancel =
True (guessing only though since I have similar code without the Exit Sub
and my code works fine).
I have similar code but without Exit Sub. I have Exit Sub later, just before
the error handling code. I don't want to run the error handling code unless
there is an actual error, so I exit before I get to that point. If you don't
have error handling or other code that you need to skip I don't think you
need to explicitly Exit Sub.