Prevent Tab Key from executing before update event

G

Guest

I set up a form with the BeforeUpdate event to test for various field inputs.
When the user keys in a record and presses the tab key to move to the next
field, the event fires. The result is that it keeps telling him that he is
missing fields that he didn't get a chance to enter. Is there a way to
prevent the tab key from firing the before update event. This should only
happen after he has a chance to enter all of the fields.

Private Sub Form_BeforeUpdate(Cancel As Integer)

If IsNull(Me.Lname) Then
Me.Lname.SetFocus
Cancel = MsgBox("You must enter a Last Name.", vbCritical, "Data
Validation
Failure")
End If
......
 
R

Rick Brandt

rmcompute said:
I set up a form with the BeforeUpdate event to test for various field
inputs. When the user keys in a record and presses the tab key to
move to the next field, the event fires. The result is that it keeps
telling him that he is missing fields that he didn't get a chance to
enter. Is there a way to prevent the tab key from firing the before
update event. This should only happen after he has a chance to enter
all of the fields.

Private Sub Form_BeforeUpdate(Cancel As Integer)

If IsNull(Me.Lname) Then
Me.Lname.SetFocus
Cancel = MsgBox("You must enter a Last Name.", vbCritical, "Data
Validation
Failure")
End If
.....

The Tab key should only cause the update events if you are tabbing into a
subform or you are at the last control in the TabOrder and tabbing is trying to
take you to the next record.

If it's the former, make your subform last in the TabOrder. If it's the latter,
set your Cycle property to Current Record and that won't happen.
 
G

Guest

It Worked. Thank you.

Rick Brandt said:
The Tab key should only cause the update events if you are tabbing into a
subform or you are at the last control in the TabOrder and tabbing is trying to
take you to the next record.

If it's the former, make your subform last in the TabOrder. If it's the latter,
set your Cycle property to Current Record and that won't happen.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top