Multiselect restrict to one if "none" selected

G

Guest

Hi,
I have a multiselect box that has a number of choices, one of which is "None"
I would like to program the box to trigger a Msgbox if "None" is selected
in addition to other choices, as they are incompatible.

One option would be to leave "none" as the default text box data, but I
don't want to do that.

I'm thinking something like:
If strselected (some parse = "None")& not "" Then
msgbox "Cannot have 'None' and other selections--must deselect one"

My current code for the box so far is:

'taking selected limits to txtLimitsfrmlbx
Private Sub lbxLimits_LostFocus()
Dim strSelected As String
Dim varSelected As Variant

For Each varSelected In Me.lbxLimits.ItemsSelected
strSelected = strSelected & _
Me.lbxLimits.Column(1, varSelected) & vbCrLf
Next varSelected
txtLimitsFrmlbx.SetFocus
txtLimitsFrmlbx.Text = strSelected
End Sub

Thank you for any ideas,
Karl
 
G

Guest

Hi Alex, thank you for responding. Trying the code, it brings up the MsgBox
when "None" is selected by itself, and that should be an acceptable response.
How should I change it the code?
Thank you very much,
Karl
 
G

Guest

Hi again,
I changed your last code to: ....ubound(split(strSelected,vbCrLf)) >1
and that took care of the glitch with "none" triggering the message box.
Thank you, again, it was very helpful,
Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top