On Tab vs. On Exit

sly like Coyote

Registered User.
Local time
Today, 10:30
Joined
Apr 14, 2010
Messages
82
I have a number of subs currently running in the on Exit event of several fields/forms/etc, and I'm starting to realize that's not really what I want. I'd prefer to have them run specifically if the user is attempting to tab quickly through the fields, but allow them to opt out if their navigating with the mouse.

Is there a similar sub call specifically for Tab key presses causing exits, or do I need to check for the key stroke?
 
What are you trying to accomplish with this exactly? Are you running data verification on the fields with your subroutines. If you want your users to be able to opt out by clicking off field with the mouse then why have the functionality in the first place? Rather than figure out how to detect a mouse click vs a Tab key, you might want to rethink your design scheme. You might find a more fail-safe way of data checking.
 
What are you trying to accomplish with this exactly? Are you running data verification on the fields with your subroutines. If you want your users to be able to opt out by clicking off field with the mouse then why have the functionality in the first place? Rather than figure out how to detect a mouse click vs a Tab key, you might want to rethink your design scheme. You might find a more fail-safe way of data checking.

It's not an issue of data verification. Generally I just want the user to be able to tab out of the final field of a subform and continue data entry uninterrupted; doing this with a SetFocus in the OnExit sub means that even if the user is trying to manually set the focus somewhere else with a direct click because they saw a typo or something still gets the focus set somewhere that seems nonsensical.

All of the subs I'm talking about are similar, not the user opting out of particular elements of data entry. I'm just not sure how to use the KeyDown or other event syntax well enough to move the SetFocus implementation there and google has not been very helpful.
 
You also need to consider how your subform is going to "know" it's on the last record. Below is the syntax for what you need.

Code:
Private Sub Field1_KeyDown(KeyCode As Integer, Shift As Integer) 'assumes your control is named Field1

If KeyCode = vbKeyTab Then
    'do something
End If

End Sub
 
Thanks. This specific bit is for a single display form, so it's clear which is the final field. during normal entry. I'd like to do something similar with the final record of a continuous form, but it's not a high priority right now.
 

Users who are viewing this thread

Back
Top Bottom