A
Andrew
I have a form with combo boxes. Based on the user's selection. a subform is
queried. (That subform then queries another, but that's not relevant to this
question.) The combo box for requestID has code like this:
If Me.cmb_requestid <> "" Then
Me.Details.Form.Filter = "[requestid] = " & Me.cmb_requestid
Me.Details.Form.FilterOn = True
Else
Me.Details.Form.FilterOn = False
End If
The combo box for the analystID has the same code -- like this:
If Me.cmb_analyst_name <> "" Then
Me.Details.Form.Filter = "[analystID] = " & Me.cmb_analyst_name.Column(0)
Me.Details.Form.FilterOn = True
Else
Me.Details.Form.FilterOn = False
End If
Each combo box works well. But now, ha ha, I want to create a procedure to
AND the filters.
I have this disaster:
If Me.cmb_requestid <> "" Or _
Me.cmb_analyst_name <> "" Then
"[requestid] = " & IIf(Me.cmb_requestid = Null, "[requestid]",
Me.cmb_requestid) & " AND [analystid] = " & IIF(Me.cmb_analyst_name.Column(0)
= Null, "[analystid]", Me.cmb_analyst_name.Column(0)
Me.Details.Form.FilterOn = True
Else
Me.Details.Form.FilterOn = False
End If
The idea being that if one or the other is null I get a WHERE clause like
this:
[requestid] = [requestid] AND [analystid] = [analystid]
but if they both have values, both criteria will appear in the WHERE clause
like this:
[requestid] = 1 AND [analystid] = 20
queried. (That subform then queries another, but that's not relevant to this
question.) The combo box for requestID has code like this:
If Me.cmb_requestid <> "" Then
Me.Details.Form.Filter = "[requestid] = " & Me.cmb_requestid
Me.Details.Form.FilterOn = True
Else
Me.Details.Form.FilterOn = False
End If
The combo box for the analystID has the same code -- like this:
If Me.cmb_analyst_name <> "" Then
Me.Details.Form.Filter = "[analystID] = " & Me.cmb_analyst_name.Column(0)
Me.Details.Form.FilterOn = True
Else
Me.Details.Form.FilterOn = False
End If
Each combo box works well. But now, ha ha, I want to create a procedure to
AND the filters.
I have this disaster:
If Me.cmb_requestid <> "" Or _
Me.cmb_analyst_name <> "" Then
"[requestid] = " & IIf(Me.cmb_requestid = Null, "[requestid]",
Me.cmb_requestid) & " AND [analystid] = " & IIF(Me.cmb_analyst_name.Column(0)
= Null, "[analystid]", Me.cmb_analyst_name.Column(0)
Me.Details.Form.FilterOn = True
Else
Me.Details.Form.FilterOn = False
End If
The idea being that if one or the other is null I get a WHERE clause like
this:
[requestid] = [requestid] AND [analystid] = [analystid]
but if they both have values, both criteria will appear in the WHERE clause
like this:
[requestid] = 1 AND [analystid] = 20