Reputation: 11
Hi am a complete noob in programming and VBA. I have created a userform and added a few comboboxes. Within the comboboxes I have created a drop down list using the With .additem EndWith function. Now every time a user presses an item within a combobox i have inserted message boxes by using codes such as this
if ComboBox1.ListIndex = 2 Then Msgbox "Do you want to open the Reports screen?", vbYesNo
The code Works but sometimes the user must press the button several times make the MsgBox appear.
I have now created a new userform and have tried to make the following
if ComboBox1.ListIndex = 1 Msgbox msg("Do you want to create a new company?", vbYesNo) = vbYes then userform1.show
The above code doesn't work but due to my lack of knowledge i don't know what else to do that's why i am here.So the above code means that if within combobox1 you go down a row and press it you should be able to get a yesNo msgbox and if you press yes then Userform1 should appear.
I know its doable because ive managed to make userform 1 appear but my problem is VByesNO.
Upvotes: 0
Views: 124
Reputation: 11
Ok so the solution - as PEH said - was to connect the condition via And
and to remove msg
.
If ComboBox1.ListIndex = 1 And Msgbox("Do you want to create a new company?", vbYesNo) = vbYes Then UserForm1.Show
instead of
If Combobox1.Listindex =1 Msgbox msg("Do you want to create a new company?", vbYesNo) = vbYes Then UserForm1.Show
Upvotes: 0