Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enable Use of Tab Key

Status
Not open for further replies.

mtwildtrout

Technical User
Oct 1, 2003
23
0
0
US
I have the following code behind the OnKeyDown event for a command button in order to disable use of the Tab Key:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 9 Then
KeyCode = 0
End If
End Sub

The form's Key Preview property has been set to True.

After leaving the command button, I would like to re-enable use of the Tab Key for the next field. How & where do I code this?
 

Can you set a variable or a tag - perhaps your CommandButton.tag to indicate whether you wish to enable tabbing through controls?

If so then - something like this:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case CommandButton.tag
Case "Lock"
If KeyCode = 9 Then
      KeyCode = 0
End If
Case Else
If Keycode = 0 Then
KeyCode = 9
End If
End Select
End Sub


Typed but not tested....
C
 
Instead of placing the code on the Form KeyDown event, why not place it on the Button KeyDown event?

Randy
 
Thanks for your quick response! I'll give your suggestions a try.
 
This thread is really old - What was I thinking?

But I was way too tired when I wrote it - at least that's what I'll claim to the VB police...

What I should have said should have been more like:

Use something like your CommandButton.tag to indicate whether you wish to enable tabbing through controls.

Then - something like this:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case CommandButton.tag
Case "Lock"
If KeyCode = 9 Then
KeyCode = 0
' and any other code needed
' in "locked situation
End If

Case Else
' other code if you need it here in
' "unlocked" situation.
End Select
End Sub

Once again - typed but not tested....

C
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top