Quote:
Originally Posted by cluce
I am trying to check and see if the user selects an item in the cbobox and if not it will display them a message but it gives me an error saying "argument not optional"
I have tried the following snippets but neither one works
can someone help me with this? thanks in advance
-
If Me.cboBeverages="" Or Me.cboDoughnuts = "" Then
-
MsgBox "A selection is required", vbCritical
-
-
else
-
'executs my code
-
end if
-
-
-
If Not Me.cboBeverages.Selected Or Not Me.cboDoughnuts.Selected Then
-
MsgBox "A selection is required", vbCritical
-
-
else
-
'executs my code
-
end if
-
If you are dealing with a combobox then if nothing is selected from it the ListIndex property of the control returns a value of -1
Consider this code which deals with the controls individually and sets the focus (places the cursor) to the relevant control if each condition is true and exits at that point so the user has to address the non selection for each control before it can pass over to continue with you code after that
- If Me!cboBeverages.ListIndex = "-1" Then
-
MsgBox "A selection is required from the beverages list", vbCritical, "Beverage Required"
-
Me!cboBeverages.SetFocus
-
Exit Sub
-
End If
-
If Me!cboDoughnuts.ListIndex = "-1" Then
-
MsgBox "A selection is required from the doughnuts list", vbCritical, "Beverage Required"
-
Me!cboDoughnuts.SetFocus
-
Exit Sub
-
End If
...Place your other execution code after the above code blocks because if they have not selected something from both combos then the other execution code will never be reached.
As relates to your second sample the .Selected property relates to a listbox not a combobox. Also which event are you placing your code for this sequence anyway? (am considering your 'argument not optional' error warning where you might have un unrelated event popping you an error that is nothing to do with this sequence)
Regards
Jim :)