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
You mean your data source for the listbox is a query? Shouldn't make any difference.mr moe said:It's based on a qry.
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.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!!!!!
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
Cosmos75 said:'Count number of selected records/items
For Each mySelection In myCtl.ItemsSelected
iCount = iCount + 1
Next mySelection
If Me.MyListBox.ItemsSelected.Count = 0 Then
Mile-O-Phile said:Little something for you Cosmos:
Code:If Me.MyListBox.ItemsSelected.Count = 0 Then![]()
That works too!Rich said:What's wrong with
If IsNull(Me.MyListBox) Then
![]()
On helping people or continuing to help despite my skill level????Rich said:you're doing just fine![]()