Reputation: 1
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
Upvotes: 0
Views: 390
Reputation: 4704
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
Upvotes: 0