TextBox_AfterUpdate acting strange

Exceladd1ct

Board Regular
Joined
Feb 10, 2019
Messages
76
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: 8

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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.
 
Upvote 0

Forum statistics

Threads
1,214,667
Messages
6,120,815
Members
448,990
Latest member
rohitsomani

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
Back
Top