I'm tempted to get the first suggestion to work because when I type-in "[1 or
2]" everything filters just fine... if I can just get the result to place an
"or" between each number.
Ah, but that temptation will lead you into a blind alley. When you
type the expression in, Access is actively interpreting what you type
and constructing the query in the background. If it works by passing
the code as a parameter I'll be very surprised.
I'm a bit confused on how to call a public function. Does the code go in a
module and then I call that function in the afterupdate of the listbox? or
the textboxt?
If it's going to work at all, which (again) I doubt, you can put the
function call right in the criteria line of the Query. Or you can put
code in the click event of a Button which you select when you've
finished selecting all the desired rows of the listbox, or in the
LostFocus event of the listbox, by just typing
=ListToText([DepartmentSelect], "OR ")
in the event line.
This is what I'm thinking so far:
Module 1 contains:
Public Function ListToText(ctl As Control, Optional Delim As String = "OR ")
As String
You can pass the Delim to the function as I wrote it -
=ListToText(Me!DepartmentSelect, "OR ")
That's why it's an optional parameter.
Dim varItm As Variant
ListToText = ""
Set ctl = Forms!frmCalendar!DepartmentSelect
Again... you don't need to have a separate function for each control,
if you pass the ctl argument when you call the function.
For Each varItm In ctl.ItemsSelected
ListToText = "[" & ListToText & ctl.Column(0, varItm) & Delim & "]"
Next varItm
End Function
DepartmentSelect (this is the mulit-select list box):
afterupdate()
me.departmentfilter = listtotext
end sub
DepartmentFilter (this is the textbox that filters each query)
afterupdate()
call requerydates
end sub
The result of ListToText isn't going anywhere and I'm sure its because I'm
not calling it right.
If you're going to try that, then in the button's Click event or the
listbox's AfterUpdate event put
Me!DepartmentFilter = ListToText(Me!DepartmentSelect, "OR ")
John W. Vinson[MVP]