sub5
Programmer
- Oct 12, 2005
- 104
Hi all
I have a query which uses a function to create a criteria. If I only select one item from my listbox then the query works OK applying the criteria returned by the function crit. However when I select more than one, the query returns nothing. When I print crit in the dubug window it returns a correct string eg something like: 10 or 11 or 14. If I cut and paste that into the query, it works. Is my problem something to do with syntax, speech marks perhaps?
I have this declaration in frm1_0Contractcreate module:
Public clnEngIDs As New Collection
I have this code in a class module clsEngID:
Public mstrengID As String
I have this code in frm1_0Contractcreate module under cmd1_click:
(Nb lstengIDselect is a multiselect listbox)
Dim frm as form, ctl as control, varItm as variant
Set frm = Forms!frm1_0Contractcreate
Set ctl = frm!lstengIDselect
For Each varItm In ctl.ItemsSelected
Dim inst As New clsEngID
inst.mstrengID = ctl.ItemData(varItm)
clnEngIDs.Add inst
Set inst = Nothing
Next varItm
I have this code in module1:
Public Function crit() As String
Dim inst As Variant, strSQL As String
For Each inst In Forms!frm1_0Contractcreate.clnEngIDs
strSQL = strSQL & " Or " & inst.mstrengID
Next
strSQL = Right(strSQL, Len(strSQL) - 4)
crit = strSQL
End Function
I have this SQL in a Query1:
SELECT [Tp-Engmaster].EngID, [Tp-Engmaster].GenericEngine
FROM [Tp-Engmaster]
WHERE ((([Tp-Engmaster].EngID)=crit()));
I have a query which uses a function to create a criteria. If I only select one item from my listbox then the query works OK applying the criteria returned by the function crit. However when I select more than one, the query returns nothing. When I print crit in the dubug window it returns a correct string eg something like: 10 or 11 or 14. If I cut and paste that into the query, it works. Is my problem something to do with syntax, speech marks perhaps?
I have this declaration in frm1_0Contractcreate module:
Public clnEngIDs As New Collection
I have this code in a class module clsEngID:
Public mstrengID As String
I have this code in frm1_0Contractcreate module under cmd1_click:
(Nb lstengIDselect is a multiselect listbox)
Dim frm as form, ctl as control, varItm as variant
Set frm = Forms!frm1_0Contractcreate
Set ctl = frm!lstengIDselect
For Each varItm In ctl.ItemsSelected
Dim inst As New clsEngID
inst.mstrengID = ctl.ItemData(varItm)
clnEngIDs.Add inst
Set inst = Nothing
Next varItm
I have this code in module1:
Public Function crit() As String
Dim inst As Variant, strSQL As String
For Each inst In Forms!frm1_0Contractcreate.clnEngIDs
strSQL = strSQL & " Or " & inst.mstrengID
Next
strSQL = Right(strSQL, Len(strSQL) - 4)
crit = strSQL
End Function
I have this SQL in a Query1:
SELECT [Tp-Engmaster].EngID, [Tp-Engmaster].GenericEngine
FROM [Tp-Engmaster]
WHERE ((([Tp-Engmaster].EngID)=crit()));