Query Parameters from a List Box

  • Thread starter Thread starter JoeCL
  • Start date Start date
J

JoeCL

Hello!

I have this report requirement that requires parameters
based on selected department codes from a list box (or
similar). How do you create a query that cam accomplish
this? Or I can ask the user to enter department codes and
query from those codes. Is this possible?

Thanks.
 
Yes. Use a loop to find all of the selected items in your listbox:
Here is an example for a listbox named List50:
it will build the IN('DX','HF','LJ') part of this where clause:
WHERE [DeptCode] IN('DX','HF','LJ')
sample Code:

Dim ListCounter, ListItems As Integer

ListItems = Me.List50.ListCount - 1
For ListCounter = 0 To ListItems
If Me.List50.Selected(ListCounter) = True Then
If Me.List50.ItemData(ListCounter) = "All" Then
strWhereClause = "like '*'"
Exit Function
Else
strList = strList & "'" & List50.ItemData(ListCounter) &
"',"
End If
End If
Next ListCounter
strWhereClause = "IN(" & Left(strList, Len(Nz(strList, 1)) - 1) & ")"
 
Back
Top