PDA

View Full Version : Tab to text boxes using



macca34
02-27-2014, 09:17 AM
I require to use the tab key to move from one textbox to another. I have found that the tab key doesnt work so I have written some code. The code works fine from tabing to the first 2 textboxes. However I have over 8 textboxes. How can I change this code to easily tab throught the form?


Private Sub CostCentre_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = vbKeyTab Then
Me.ProgCode.Activate
End If
Exit Sub

Thanks

mrojas
02-28-2014, 05:30 PM
Is the TabStop property of each of your text boxes set to True? If is the TabIndex properly numbered?

macca34
03-03-2014, 06:13 AM
I have managed to get the code to work (i.e above example). It's just that for each textbox I have to create the same code each time. I'm new to VBA and was hoping that there might have been some 'Loop' option were it would have saved me writing the code 10 times!
Thanks

fumei
03-03-2014, 07:48 AM
You can programmatically loop through controls, but yes, each controls has its own code. So code for a control is separate for code for another control.

mrojas
03-03-2014, 08:01 AM
You could put the cider in a subroutine and call it from each control. You'd still have to repeat the code 10 times but you would only have to add one line of code for each control
Private Sub s_Tab
Your code goes here
End Sub

In each control add Call s_Tab

SamT
03-03-2014, 12:00 PM
If using VBA UserForm, you don't need Tab-Key code.

In VBA, with UserForm in right hand Pane, Press F4 to view Properties Window.

Click on a Form Control to see Property Pane for that control.

See: mrojas post #2 (http://www.vbaexpress.com/forum/showthread.php?49050-Tab-to-text-boxes-using&p=305750&viewfull=1#post305750) for more Info.

For more help, click on property Name in Property Pane and press F1