Excel VBA ComboBox1_DropButtonClick Event -
i got macro below fires twice (showing same messagebox twice). first when combobox1 opens , sec when combobox1 closes.
private sub combobox1_dropbuttonclick() if me.combobox2.text = "" msgbox "fill text box" else 'do stuff end if end sub
is there way create show messagebox once. want user select value in combobox1 first before clicking on combobox2 dropbutton.
here unelegant work-around using "count" variable prompts msgbox first , not sec time.
dim count integer private sub combobox1_dropbuttonclick() count = count + 1 if me.combobox2.text = "" if count = 1 msgbox "fill text box" else count = 0 end if else 'do stuff end if end sub
however, highly suggest utilize combobox1_change()
event if it's not necessary utilize drop button one.
p.s.: declaration of "count" variable needs remain out of method. due fact that:
if stays inside, it's local variable of method , loses modifications every time method ended; if stays outside, maintain modifications 1 time method has ended run. excel vba excel-vba
No comments:
Post a Comment