Hello,
On my project I'm using this code from this site
http://www.tek-tips.com/faqs.cfm?fid=6099 to allow multi selection in a listbox . It works fine.
My list box lstClients is feeded by the field Client Name from my only table.
I have added the option (All) to my list box by using a union query (not sure this is the best way to do this by the way).
The issue is that I don't know how to adapt the code to basically tell "If the user selects "(All)" then you can consider that this is equivalent to select everything"
I tried to replace this part:
If lbo.ItemsSelected.Count = 0 Then
IsSelectedVar = True 'return all if no items selected
by
If strListBoxName.Value = "(All)" Then
IsSelectedVarClients = True 'return all if no items selected
... without success.
Any idea?
Many thanks,
Here is the code:
Code:
Function IsSelectedVarClients( _
strFormName As String, _
strListBoxName As String, _
varValue As Variant) _
As Boolean
'strFormName is the name of the form
'strListBoxName is the name of the listbox
'varValue is the field to check against the listbox
Dim lbo As ListBox
Dim item As Variant
If IsNumeric(varValue) Then
varValue = Trim(Str(varValue))
End If
Set lbo = Forms(strFormName)(strListBoxName)
If strListBoxName.Value = "(All)" Then
IsSelectedVarClients = True 'return all if no items selected
Else
For Each item In lbo.ItemsSelected
If lbo.ItemData(item) = varValue Then
IsSelectedVarClients = True
Exit Function
End If
Next
And my union query:
SELECT T_NewLaunches.[Client Name] FROM T_NewLaunches UNION SELECT "(All)" FROM T_NewLaunches