Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Autotab

Status
Not open for further replies.

bpeirson

Structural
Apr 7, 2003
147
I have a userform with a combobox, textbox and button set in that sequence in the tab order. The combobox and the text box both have autotab enabled, this automatically tabs to the next item when enter is pressed.

Can I make the button behave in the same way?

I tried to use VBA code to cause the first tab item to be selected after the button was clicked but I have had no luck.
 
Replies continue below

Recommended for you

Not sure which application you are using, but from the Excel VBA Help file:

AutoTab Property
Specifies whether an automatic tab occurs when a user enters the maximum allowable number of characters into a TextBox or the text box portion of a ComboBox


and in the Applies To list:
ComboBox Control
TextBox Control


This property would appear to have no use in the context of a CommandButton.


Regards,
Mike
 
Just select the other control that you want to select at the end of the click event for the button.
 
Most controls have a SetFocus Method - use that at the end of the Command click event code

Code:
Private Sub CommandButton1_Click()
'do the other click things here like maybe
'ComboBox1.AddItem TextBox1.Text
'then set focus to the Textbox
[COLOR=red]TextBox1.SetFocus[/color]
End Sub

Good Luck
johnwm
________________________________________________________
To get the best from these forums read faq731-376 before posting

Steam Engine enthusiasts:
 
Thanks, I could only find select case in the help files (after reading AliThePro's advice). I am used to Excel commands so I was searching for things like select, activate & move to which all went nowhere.
 
I have used the SetFocus method but when the focus is set on the combo box I can only scroll through existing text. If I want to enter new text or even modify existing text (use the delete key to remove letters) I have to either click in the box or tab out of focus then tab back into the box.

It is nice to be 1 step closer to the goal but any additional help is appreciated. The VBA help does not list any methods applicable to the combo box which might do what I need.

I will try looking at methods for related objects.
 
Look at the SelStart property

Good Luck
johnwm
________________________________________________________
To get the best from these forums read faq731-376 before posting

Steam Engine enthusiasts:
 
It seems the SelStart property can only return the cursor position. I can't figure out how to set the cursor position.
 
To position the cursor at the start:
Code:
Textbox1.SelStart = 0
To get to the end
Code:
Textbox1.SelStart = Len(Textbox1.Text) + 1

Good Luck
johnwm
________________________________________________________
To get the best from these forums read faq731-376 before posting

Steam Engine enthusiasts:
 
Not working as suggested.

Could it be that I am using a ComboBox rather than a TextBox?
 
Sorry, my bad! I was thinking about the TextBox still. To select a particular item in a ComboBox, use the ListIndex property (zero based)

ComboBox1.ListIndex = 1

will select the second item in the list


Good Luck
johnwm
________________________________________________________
To get the best from these forums read faq731-376 before posting

Steam Engine enthusiasts:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor