loop until confusing

zmhnk

Board Regular
Joined
Jan 23, 2012
Messages
79
hi ...

i have form with combo box and button add when i choose the name form combo box and press add the form work good, what i need is, when the user didnt choose one of the values from combobox and hit the button add, msg will show to user "Please choose one value from combo box " ,

and the msg will disappear when the user choose the value from combo box and hit add button

i try something like this :

Code:
[COLOR=Red][B]
if (CmbNames.value="") then
do
loop until (CmbNames.value<>"")
msgbox [COLOR=DeepSkyBlue]"Please choose one value from combo box " [/COLOR]
end if 
loop[/B][/COLOR]

so what is the wrong ???/
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
If they are to press a button , then what about putting the macro in the button press. Start it with

if (CmbNames.value="") then exit sub
 
Upvote 0
^^ Correct. Just use the button click event, not a do loop.

Code:
Sub Button1_Click()

If Len(CmbNames.value)=0 then
    Exit Sub 
Else
    'Do stuff
End If

End Sub

I use the Len() function by habit to account for null values and zero-length strings indifferently. That may be overkill here but in any case that's my tried and true for testing for blanks/nulls/empty strings etc.
 
Upvote 0
You could Enable\Disable the Add button (btnAdd) if the combobox (CmbNames) has a value.

Set the default property of the button to Enabled = False.

Then this will set the enabled propery to true if the combobox has a value.

Code:
Private Sub CmbNames_Change()
    btnAdd.Enabled = CmbNames.Value <> ""
End Sub
 
Upvote 0
thnx guys for all ur help , but i want the msg appear when the string is empty until the string is not empty
 
Upvote 0
Just put an asterisk by the combobox:

Enter XXX (*Required): ____________


User doesn't need a message box to know if a value is entered since that can be seen without a message box or handled on the button click event. In any case, VBA message boxes are modal and would prevent a value being selected (they wouldn't be able to select any value while the message box is showing, but the message would show as long as they haven't selected a value, so it becomes an infinite loop with no exit point).
 
Upvote 0

Forum statistics

Threads
1,206,761
Messages
6,074,781
Members
446,088
Latest member
Koustubh12

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top