1

I am writing an If statement to test if I i have an option selected in two combo boxes. The combo box being checked is generated from array with two values. One of those cells are blank so the top value is blank in the combo box.

My if statement is
The array is

 Private Sub cbApplicationSelection_Change()
   If (eMassWelcome.cbwesitechoose.text = "") Then
   eMassWelcome.cbApplicationSelection.text = ""
   MsgBox "A website has not been selected. Please select a website from the dropdown and try again."
   End If
   Exit Sub
 End Sub

This works.

The problem is the pop up comes up 3 times and im not sure why. I've tried IsNull() and listindex = -1. IsNull() did not work and list index gave me the same result as above. All this is being done with vba in excel.

ShanayL
  • 1,217
  • 2
  • 14
  • 29
  • This might be helpful: http://stackoverflow.com/questions/23186829/why-is-a-excel-vba-combobox-change-event-triggering-every-time-one-of-its-prop – Rich Holton Apr 04 '17 at 16:10
  • Have you placed any change event for cbApplicationSelection? If so, as you are changing it's value, the change event will also get triggered. – Subodh Tiwari sktneer Apr 04 '17 at 16:46
  • Yes, I have an else statement for if all fields have values and it works fine. I have that `Exit Sub` there so the change event for cbApplicationSelection does not get triggered. – ShanayL Apr 04 '17 at 17:00
  • that did help and explained a lot. It suggested I get the combo box to generate from an array which i did but I still get them same issue – ShanayL Apr 04 '17 at 18:32
  • ok i get what sktneer was saying now. Once i looked at it I took out the cbApplicationSelection line and it displayed once like it is supposed to. – ShanayL Apr 04 '17 at 18:43
  • @sktneer please post your comment as the answer. – ShanayL Apr 18 '17 at 16:58
  • Done. Added my comment as an answer as per your request. – Subodh Tiwari sktneer Apr 18 '17 at 17:01

1 Answers1

0

Have you placed any change event for cbApplicationSelection? If so, as you are changing it's value, the change event will also get triggered.

Private Sub cbApplicationSelection_Change()
   If eMassWelcome.cbwesitechoose.text = "" Then
   MsgBox "A website has not been selected. Please select a website from the dropdown and try again."
   End If
 Exit Sub
End Sub
Subodh Tiwari sktneer
  • 9,906
  • 2
  • 18
  • 22