0
votes

I have private sub textbox1_keydown and private sub textbox1_afterupdate. If im finish filling up textbox1 then clicking the combobox still populates it with lists. But when im finish filling up textbox1 then pressing the enter key the combobox populates a abnormal lists. cmbo4 is a sub event where it populates the combobox based on what i input in the textbox1. My codes in on a userform

Heres my code:

Private sub TextBox1_KeyDown(ByVal KeyCode As_ 
MSForms.ReturnInteger,ByVal Shift As Integer)
If KeyCode=13 Then
ComboBox4.Clear
Call cmbo4
ComboBox4.DropDown
ComboBox4.SetFocus
End If
End Sub

Now i have this textbox1_afterupdate event, im adding this event to avoid errors to my program when the user wants to use the mouse to click the next combobox and not by pressing enter.

Private Sub TextBox1_AfterUpdate()
ComboBox4.Clear
Call cmbo4
ComboBox4.DropDown
ComboBox4.SetFocus
End Sub

My problem is to stop the event textbox1_afterupdate to perform when the user press the enter key so that my combobox wont have abnormal lists

1
Why don't you use the Exit Event instead of KeyDown and Afterupdate? - EvR
I tried it but combobox4.clear, combobox4.dropdown and combobox.setfocus wont effect..only the cmbo4 sub event runs - Tristan300
You could Add the combobox4.dropdown and combobox.setfocus in your cmbo4 (public in a module) and call it with application.ontime - EvR

1 Answers

0
votes
Option explicit
Dim InProgress as boolean  'module level variable

Private sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,ByVal Shift As Integer)
If KeyCode=13 Then
     ComboBox4.Clear
     Call cmbo4
     ComboBox4.DropDown
     ComboBox4.SetFocus
     InProgess = true
End If
End Sub

Private Sub TextBox1_AfterUpdate()
if inProgress then  'we just updated it so don't repeat
     inprogress = False  'just clear the event
else
     ComboBox4.Clear
     Call cmbo4
     ComboBox4.DropDown
     ComboBox4.SetFocus
     inprogress = False 'and clear the event
End IF
End Sub