Hi,
I have 25 text boxes in my form. While design i have assigned some tabindex.But while checking the entries in the text boxes i want to move the focus to the other box irrespective of the tab index. Is it possible..
Dana
Printable View
Hi,
I have 25 text boxes in my form. While design i have assigned some tabindex.But while checking the entries in the text boxes i want to move the focus to the other box irrespective of the tab index. Is it possible..
Dana
Use the SetFocus method of the control.
Text4.SetFocus
An error will occur if the control is not Visible or not Enabled so check before calling its SetFocus method
it is not working.The control not moving even if setfocus.i have written this in validate event of text box
Post your code.
If you want to tab from textbox to textbox see the How to trap the Tab key example in my signature.
you could assign alt-keys to the textboxes and then use the comination you needQuote:
Originally Posted by danasegarane
It can't be done in validate event, do it in LostFocus event.Quote:
Originally Posted by danasegarane
It appears you cannot use SetFocus in the Validate event. Keep your "validation" code in the Validate event but use the LostFocus to decide which control to move to next.Quote:
it is not working.The control not moving even if setfocus.i have written this in validate event of text box
Example. 4 TextBoxes on a form. TabOrder is Text1, Text2, Text3, Text4. Change Text1 to a 3 or 4 and hit Tab
VB Code:
Private Sub Text1_Validate(Cancel As Boolean) If Not IsNumeric(Text1.Text) Then MsgBox "Invalid Data" Cancel = True End If End Sub Private Sub Text1_LostFocus() Select Case Text1.Text Case "3" Text3.SetFocus Case "4" Text4.SetFocus Case Else 'anything else and focus is set to Text2 'which is the next control in the TabOrder End Select End Sub Private Sub Form_Load() Text1.Text = "1" Text1.MaxLength = 1 End Sub
This code did not work, Text2 was always the next control to get Focus.
VB Code:
Private Sub Text1_Validate(Cancel As Boolean) If Not IsNumeric(Text1.Text) Then MsgBox "Invalid Data" Cancel = True Else Select Case Text1.Text Case "3" Text3.SetFocus Case "4" Text4.SetFocus Case Else 'anything else and focus is set to Text2 'which is the next control in the TabOrder End Select End If End Sub