Multi Select

mr moe

Registered User.
Local time
Today, 05:20
Joined
Jul 24, 2003
Messages
332
Do you guys know how I can force the user to make a selection from the multi select. The multi select I have comes from a table which can grow or shrink therefore. Thanks.
 
This is a multi select, I don't think that you can set it to be required. I don't want the user to click on the run button before he/she selects a value from the multiselect because they will get an error if they have not choosen anything!!!!!
 
Oh, it's not bound to a field in a table. (?)

I quess the only way would be to loop through the entire list to see if any one of them has been selected and then kick off the code based on those results...

???
 
mr moe,

Adapt this code to suit your needs
Code:
    Dim myFrm As Form, myCtl As Control
    Dim mySelection As Variant
    Dim iSelected, iCount As Long

    [COLOR=DarkGreen]'Set myForm to this form (frmMultiSelectListBox)[/COLOR]
    Set myFrm = Me
    [COLOR=DarkGreen]'Set myCtl to listbox[/COLOR]
    Set myCtl = Me.lstName

    iSelected = 0
    iCount = 0

    [COLOR=DarkGreen]'Count number of selected records/items[/COLOR]
    For Each mySelection In myCtl.ItemsSelected
        iCount = iCount + 1
    Next mySelection
    

    If iCount = 0 Then
        [B][COLOR=DarkGreen]'Code to run if nothing is selected[/COLOR]
        MsgBox "There are no selections to show..", _
        vbInformation, "Nothing selected!"[/B]
    End If
See Multiple Selection ListBox Sample Database.
 
Last edited:
It's based on a qry. I don't know how to start the code of looping. I know how to do it this way. If my_multi_select.list.selected(0) = false then msgbox"you must pick something"
The thing is that the multi select list changes therefore I don't know how to loop through it. can you help?
 
It's based on a qry. I don't know how to start the code of looping. I know how to do it this way. If my_multi_select.list.selected(0) = false then msgbox"you must pick something" note: selected(0) is the first item in the list.
The thing is that the multi select list changes therefore I don't know how to loop through it. can you help?
 
mr moe said:
It's based on a qry.
You mean your data source for the listbox is a query? Shouldn't make any difference.
mr moe said:
I don't want the user to click on the run button before he/she selects a value from the multiselect because they will get an error if they have not choosen anything!!!!!
So you want to ensure that something is selected before this button is pressed. Just adapt the code to your form and put in in the click even for the button.

For the bolded code, makes sure you add a line to exit the sub so that it will not execute the rest of button code until something is selected
Code:
    If iCount = 0 Then
        [COLOR=DarkGreen]'Code to run if nothing is selected[/COLOR]
        MsgBox "Please select something from the listbox first!", _
        vbInformation, "Nothing selected!"
        [b][COLOR=Navy]Exit Sub[/COLOR][/b]
    End If
You can also add a line to set the focus back to the listbox.
 
Cosmos75 said:
'Count number of selected records/items
For Each mySelection In myCtl.ItemsSelected
iCount = iCount + 1
Next mySelection

Little something for you Cosmos:

Code:
If Me.MyListBox.ItemsSelected.Count = 0 Then

;)
 
(If Me.MyListBox.ItemsSelected.Count = 0 Then) = cool
 
Good tip!

Mile-O-Phile said:
Little something for you Cosmos:
Code:
If Me.MyListBox.ItemsSelected.Count = 0 Then
;)
:o

LOL!

Thanks for that tip, if I get time I'll add it to the sample db I've got out there.
 
Rich said:
What's wrong with
If IsNull(Me.MyListBox) Then
:confused:
That works too!
:D

I am beginning to think I shouldn't even bother trying to help at this point as it is becomming painfully obvious that my skills are not up to par...
:o

not that it has ever stopped me from trying!
:p
 
'If IsNull(Me.MyListBox) Then' = i be darn
 

Users who are viewing this thread

Back
Top Bottom