I have a field on my form that is required for all new records created. This
is the code I have in the BeforeUpdate event on my form.
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.RequestedBy) Then
MsgBox "You Must Select Your Name!"
Cancel = True
Me.RequestedBy.SetFocus
End If
End Sub
It doesn't seem to be working properly. Right now if I created a new record
and didn't fill in that field and just clicked the close button on my form I
do get the msgbox but then the form closes. Am I missing something here? It
doesn't set the focus on that field the way it's written in the code. I also
have this field flagged as required in the table. What am I doing wrong?
>I have a field on my form that is required for all new records created. This
>is the code I have in the BeforeUpdate event on my form.
[quoted text clipped - 17 lines]
>doesn't set the focus on that field the way it's written in the code. I also
>have this field flagged as required in the table. What am I doing wrong?
Did you actually *create a new record* - by dirtying some *other* field? If
not, then the BeforeUpdate event will not fire, because there's nothing to
update. You're just opening a blank, uninitialized record and then closing it.
If you did in fact enter data into some other field, then there's clearly
something wrong - more details please!
John W. Vinson [MVP]