Prevent Tab Key from executing before update event

  • Thread starter Thread starter Guest
  • Start date Start date
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
......
 
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.
 
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.
 
Back
Top