0
votes

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.

1
Your second code fragment lacks a Then hence is a syntax error. In any event, if all you give are code fragments without adequate context, you aren't going to get an answer. Please give a minimal reproducible exampleJohn Coleman
In addition to the above, you don't need msg( and you could use if ComboBox1.ListIndex = 1 and Msgbox ("Do you want to create a new company?", vbYesNo) = vbYes then This would have been clear from the help on msgbox not experience/years coding.Nathan_Sav
That worked perfectly thank you so much. I have entered the And function like you said . The msg function was a mistake I made when I wrote the code. Then again thank you so much for your help I tried to find a solution to the problem for the past week now .Kyriacos Evgeniou

1 Answers

0
votes

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