How to jump between TextBoxes

  • Thread starter Thread starter jose luis
  • Start date Start date
J

jose luis

Hi Forum

I have several Textboxes from Controls Menu in a sheet. I need to make
jump the cursor after a keypressing "enter", "Tab" or "Arrow Keys" to
the next TextBox. Today to jump to the next Textbox I have to Click
with the mouse over the next Textbox. I thought was a properties
problem but i haven't found the solution.

Could you lead me in the right direction.?

Thanks in advance to all of you in the Forum where the information
turns to Knowlegde.

Regards

Jose Luis
 
Hi Jose

You have to code this, one by one, for controls on worksheets. Like

Private Sub TextBox1_KeyDown(ByVal KeyCode As _
MSForms.ReturnInteger, ByVal Shift As Integer)
Select Case KeyCode
Case 9, 13, 39
KeyCode = 0
TextBox2.Activate
Case Else
End Select
End Sub

The Forum that you praise is just a Usenet frontend. It sends your question
to a Usenet newsgroup, pulls our replies back and puts an ad or two beside
it without asking us. See
http://www.mvps.org/dmcritchie/ie/oe6nws01.htm
on how to connect directly to the real thing.

HTH. Best wishes Harald
 
Here is a way

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
Dim bBackwards As Boolean


Select Case KeyCode
Case vbKeyTab, vbKeyReturn, vbKeyDown, vbKeyUp
Application.ScreenUpdating = False
bBackwards = CBool(Shift And 1) Or (KeyCode = vbKeyUp)
'Excel 97 must select cell before activating another control.
If Application.Version < 9 Then Sheet1.Range("A1").Select
If bBackwards Then
TextBox3.Activate
Else
TextBox2.Activate
End If
Application.ScreenUpdating = True
End Select
End Sub

Private Sub TextBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
Dim bBackwards As Boolean


Select Case KeyCode
Case vbKeyTab, vbKeyReturn, vbKeyDown, vbKeyUp
Application.ScreenUpdating = False
bBackwards = CBool(Shift And 1) Or (KeyCode = vbKeyUp)
'Excel 97 must select cell before activating another control.
If Application.Version < 9 Then Sheet1.Range("A1").Select
If bBackwards Then
TextBox1.Activate
Else
TextBox3.Activate
End If
Application.ScreenUpdating = True
End Select
End Sub

Private Sub TextBox3_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
Dim bBackwards As Boolean


Select Case KeyCode
Case vbKeyTab, vbKeyReturn, vbKeyDown, vbKeyUp
Application.ScreenUpdating = False
bBackwards = CBool(Shift And 1) Or (KeyCode = vbKeyUp)
'Excel 97 must select cell before activating another control.
If Application.Version < 9 Then Sheet1.Range("A1").Select
If bBackwards Then
TextBox2.Activate
Else
TextBox1.Activate
End If
Application.ScreenUpdating = True
End Select
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.
 
Hi all,

I just found this code in some part of this forum, just what i needed.

Thanks to the Forum, past, present, and future members.


Jose Luis



Private Sub TextBoxCurrent_KeyDown(ByVal KeyCode As
MSForms.ReturnInteger, _
ByVal Shift As Integer)

Dim bBackwards As Boolean
Select Case KeyCode
''' These are the only keys we care about.
Case vbKeyTab, vbKeyReturn, vbKeyDown, vbKeyUp
Application.ScreenUpdating = False
''' Determine if we need to move backwards.
bBackwards = CBool(Shift And 1) Or (KeyCode = vbKeyUp)
''' In Excel 97 we must select a cell
''' before activating another control.
If Application.Version < 9 Then Sheet1.Range("A1").Select
''' Activate the appropriate control based on key(s) pressed.
If bBackwards Then TextBoxPrevious.Activate Else _
TextBoxNext.Activate
Application.ScreenUpdating = True
End Select
End Sub
 

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

Back
Top