Yes, IsSelectedVar is a public function in a module. If Has Module is No, and
I open the query and click Run, the query returns the result expected based
on the selection from the listbox. As soon as it is set to Yes so that an
'OK' button will run, I get the error, even trying to just run the query
separately without the button. I've tried using a simple DoCmd.OpenQuery
"qryFindRoHS_FromSupplierList", acViewNormal to run the query, figuring if I
can just click Run and it works, this should work also. I can't figure out
why setting that 1 property causes an error running a query.
Here's the function and the SQL of a simple query I'm trying to run:
Function IsSelectedVar( _
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 lst As ListBox
Dim item As Variant
If IsNumeric(varValue) Then
varValue = Trim(Str(varValue))
End If
Set lst = Forms(strFormName)(strListBoxName)
For Each item In lst.ItemsSelected
If lst.ItemData(item) = varValue Then
IsSelectedVar = True
' Exit Function
End If
Next
End Function
SELECT Parts.*
FROM Parts
WHERE (((IsSelectedVar("frmFind_RoHS_Status","lstSupplier",[Supplier
Name]))=-1));
Is IsSelectedVar( ) a public function residing in a module? Do you
use distinct syntax to differentiate between fields, controls, and
variables? Is there any chance that two items share the same name?
How are you calling the query? A command button can call a query four
or five different ways... Has Module determines whether there is a
place for form code, a place to add code for events. If you aren't
coding events, then how are you operating? Through macros?- Hide quoted text -
- Show quoted text -