Tab from one Text Box to a different Text Box

  • Thread starter Thread starter German
  • Start date Start date
G

German

I am creating a user interface using text boxes (activex controls) and
I want to be able and tab from one text box to the next. The text
boxes are located on the sheet itself not in a form. Does anyone know
if this can be done.

Thanks.
 
Here is code Rob Bovey previously posted related to tabbing through controls
on a worksheet:

From: Rob Bovey ([email protected])
Subject: Re: Worksheet Controls

Newsgroups: microsoft.public.excel.programming
Date: 2000/07/22


Hi Fabio,

<<1 - Is there a way to establish the tab order of worksheet controls, or
even
have the Tab or Enter key select them continuously ( as they do in cells)?>>

There's no automatic way of doing it that I know. You have to do it
yourself
using the KeyDown event for each of the controls on your worksheet. If the
KeyCode argument of the KeyDown event for a given control tells you that TAB
or
ENTER has been pressed, you explicitly activate the control that you want to
be
next in line. Here's a simple example:

Private Sub TextBox2_KeyDown( _
ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
''' Check if the TAB or ENTER key was pressed.
If KeyCode = vbKeyTab Or KeyCode = vbKeyReturn Then
''' If this is Excel 97 you must select a cell
''' before attempting to activate another control.
If Val(Application.Version) < 9 Then
Me.Range("A1").Select
End If
''' Move the focus appropriately.
If CBool(Shift And 1) Then
''' The user was holding down the SHIFT key
''' move back to the previous control.
TextBox1.Activate
Else
''' Move to the next control.
TextBox3.Activate
End If
End If
End Sub
 
Back
Top