As you can see I posted the wrong part of the code. I did
not mention the other query critera but they are all
included in the code as follows:
SELECT *
FROM [Diagnoses Report Query]
WHERE ((([Diagnoses Report Query].UNIT)=[Forms]!
[DiagnosesBuildingForm]![cboUnitFirst] And ([Diagnoses
Report Query].UNIT) Between [Forms]!
[DiagnosesBuildingForm]![cboUnitFirst] And [Forms]!
[DiagnosesBuildingForm]![cboUnitLast]) AND ((InParam
([Diagnoses Report Query].[Unit],[Forms]!
[DiagnosesBuildingForm]![txtValList]))=True)) OR
((([Diagnoses Report Query].UNIT) Between [Forms]!
[DiagnosesBuildingForm]![cboUnitFirst] And [Forms]!
[DiagnosesBuildingForm]![cboUnitLast]) AND ((InParam
([Diagnoses Report Query].[Unit],[Forms]!
[DiagnosesBuildingForm]![txtValList]))=True) AND (([Forms]!
[DiagnosesBuildingForm]![cboUnitFirst]) Is Null)) OR
((([Diagnoses Report Query].UNIT)=[Forms]!
[DiagnosesBuildingForm]![cboUnitFirst]) AND ((InParam
([Diagnoses Report Query].[Unit],[Forms]!
[DiagnosesBuildingForm]![txtValList]))=True) AND (([Forms]!
[DiagnosesBuildingForm]![cboUnitLast]) Is Null)) OR
(((InParam([Diagnoses Report Query].[Unit],[Forms]!
[DiagnosesBuildingForm]![txtValList]))=True) AND (([Forms]!
[DiagnosesBuildingForm]![cboUnitFirst]) Is Null) AND
(([Forms]![DiagnosesBuildingForm]![cboUnitLast]) Is Null))
OR ((([Diagnoses Report Query].UNIT)=[Forms]!
[DiagnosesBuildingForm]![cboUnitFirst] And ([Diagnoses
Report Query].UNIT) Between [Forms]!
[DiagnosesBuildingForm]![cboUnitFirst] And [Forms]!
[DiagnosesBuildingForm]![cboUnitLast]) AND (([Forms]!
[DiagnosesBuildingForm]![txtValList]) Is Null)) OR
((([Diagnoses Report Query].UNIT) Between [Forms]!
[DiagnosesBuildingForm]![cboUnitFirst] And [Forms]!
[DiagnosesBuildingForm]![cboUnitLast]) AND (([Forms]!
[DiagnosesBuildingForm]![cboUnitFirst]) Is Null) AND
(([Forms]![DiagnosesBuildingForm]![txtValList]) Is Null))
OR ((([Diagnoses Report Query].UNIT)=[Forms]!
[DiagnosesBuildingForm]![cboUnitFirst]) AND (([Forms]!
[DiagnosesBuildingForm]![cboUnitLast]) Is Null) AND
(([Forms]![DiagnosesBuildingForm]![txtValList]) Is Null))
OR ((([Forms]![DiagnosesBuildingForm]![cboUnitFirst]) Is
Null) AND (([Forms]![DiagnosesBuildingForm]![cboUnitLast])
Is Null) AND (([Forms]![DiagnosesBuildingForm]!
[txtValList]) Is Null));
I know it should be shorter but I'm not skilled enough to
do it.
Two parts of this code does not work correctly. One is the
problem mentioned below (only 13 units or less return
records in the InParam statements) the other is
the "Between" "And" which should allow me to select a
range of units but only returns the first record.
My code for InParam is as follows:
Function GetToken(stLn, stDelim)
Dim iDelim As Integer, stToken As String
iDelim = InStr(1, stLn, stDelim)
If (iDelim <> 0) Then
stToken = LTrim$(RTrim$(Mid$(stLn, 1, iDelim - 1)))
stLn = Mid$(stLn, iDelim + 1)
Else
stToken = LTrim$(RTrim$(Mid$(stLn, 1)))
stLn = ""
End If
GetToken = stToken
End Function
Function InParam(fld, Param)
Dim stToken As String
If IsNull(fld) Then fld = ""
Do While (Len(Param) > 0)
stToken = GetToken(Param, ",")
If stToken = LTrim$(RTrim$(fld)) Then
InParam = -1
Exit Function
Else
InParam = 0
End If
Loop
End Function
Thanks,
Dennis