Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 05-11-2009
Member
 
Join Date: Mar 2009
Posts: 1,360
Moving from one TextBox to another with TAB

I have an Excel spreadsheet with hundreds of TextBox. I wish I could move from one to another with Tab key. For the moment I have coded to go from 1 to 2:

Code:
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = vbKeyTab Then
        TextBox2.Activate
    End If
End Sub
It works, but I am obliged to duplicate the code 99 times for 99 more TextBox!

Is there a way to code the thing once for all of the TextBox, from N to N +1?
Reply With Quote
  #2  
Old 05-11-2009
Member
 
Join Date: Nov 2008
Posts: 1,054
Re: Moving from one TextBox to another with TAB

Hello, please note that it can not work, probably TextBox2.SetFocus will be useful but surely not TextBox2.Activate. Without knowing what you do with your textboxes, an example is as follows:

Quote:
The following Extensible Application Markup Language (XAML) example describes a simple TextBox control named tbFocusMe
Code:
<TextBox Name="tbFocusMe">
  This is the text in my text box.
</TextBox>
The following example calls the Focus method to set the focus on the TextBox control with the Name tbFocusMe.

In Visual Basic:

Code:
tbFocusMe.Focus()
In C#:

Code:
tbFocusMe.Focus();
source: microsoft.com
Reply With Quote
  #3  
Old 05-11-2009
Member
 
Join Date: Nov 2008
Posts: 1,022
Re: Moving from one TextBox to another with TAB

In design mode, when you do a right click on your textbox, you have a parameter TabKeyBehavior which when true, accepts the change of textbox by pressing the tab.

TextBox.TabKeyBehavior Property: Returns or sets a Boolean that specifies whether tabs are allowed in the edit region. Read/write.

True if pressing TAB inserts a tab character in the edit region.
False if pressing TAB moves the focus to the next object in the tab order (default).
Reply With Quote
  #4  
Old 05-11-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: Moving from one TextBox to another with TAB

But why are you doing that through VBA code? In fact there is no need of any coding to achieve the same. The 'Tab' should be having such a property of the text boxes. TabStop property should be set to True, and it must have a TabIndex (that is the order the tab key that you need to be followed).
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Moving from one TextBox to another with TAB"
Thread Thread Starter Forum Replies Last Post
Excel/VBA: Copying text from UserForm Textbox to a Worksheet Textbox Neil Ives Software Development 2 20-08-2010 01:23 AM
Textbox validation in ASP.NET Kasper Software Development 4 19-01-2010 08:28 PM
how to hide a textbox in asp.net Alejandro Software Development 2 10-06-2009 10:43 AM
How to recover a value in a textbox S_Asnodkar Software Development 4 29-04-2009 03:37 PM
Numeric TextBox in VB.NET Gauresh Software Development 0 22-12-2008 05:18 PM


All times are GMT +5.5. The time now is 11:08 AM.