TextBox_AfterUpdate acting strange

Exceladd1ct

Board Regular
Joined
Feb 10, 2019
Messages
64
I am trying to set focus and activate the dropdown of a combobox in the After_Update Subroutine of a Textbox. After filling in some text, if i move focus away from the textbox by mouse click, it works fine, if i move the focus away by pressing enter key, it jumps to the 3rd textbox instead of combobox.

I managed to do the job with KeyDown event but, what am i missing? why does it jump to txtbox3 when pressing enter key?

VBA Code:
Private Sub TextBox1_afterupdate()
Call combo
End Sub

'Without this, it won't work
Private Sub textbox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = 13 Then
        If TextBox1.Value <> "" Then
            combo
        Exit Sub
    End If
    End If
End Sub

Function combo()
UserForm4.ComboBox1.SetFocus
UserForm4.ComboBox1.DropDown
End Function
 

Attachments

  • 2021-01-01_12h49_06.png
    2021-01-01_12h49_06.png
    3.9 KB · Views: 3

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
12,432
Office Version
  1. 365
Platform
  1. Windows
Check the tab index for each of the objects in the form. The default order is the order in which you added them to the form regardless of the form layout.

TabIndex 0 is the default focus when the form is opened, from there each press of tab / enter will move to the next object based on the index number.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,355
Messages
5,624,207
Members
416,017
Latest member
moritz210

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top