T
TESA0_4
Hi,
I have created a form with two unbound combo boxes. One allows the user to
select a code that represents a type of risk and the other allows the user to
select a code that represents a location. I am building a query that
includes the unbound combo boxes as selection criteria.
The user must select a risk type but need not necessarily select a location
code. If they select only a risk type and no location code I want the query
to return all records with the selected risk type and a null location value.
(Risk type is always populated whereas location is optional). If the use
selects a risk type and location code then I want the query to return records
where the risk type and location value match the user's selections.
I find that when I insert [Forms]![frmRegisterSearch]![comboLocation] in the
query criteria all works well if a non-null value is selected in the location
combo control, but if the combo control is left blank, the query does not
return any values.
I have tried inserting code like:
IIf(IsNull([Forms]![frmRegisterSearch]![comboLocation]),Null,[Forms]![frmRegisterSearch]![comboLocation]) but this does not work.
The SQL View of my current code is:
SELECT tblRegister.RegID, tblRegister.Type, tblRegister.Locn,
tblRegister.Manufacturer, tblRegister.Model, tblRegister.Archived
FROM tblRegister
WHERE (((tblRegister.Type)=[Forms]![frmRegisterSearch]![comboRiskType1]) AND
((tblRegister.Locn)=IIf(IsNull([Forms]![frmRegisterSearch]![comboLocation]),Null,[Forms]![frmRegisterSearch]![comboLocation])));
I realise my question is very similar to other questions on this site but I
just don't seem to be able to grasp how the other replies apply to my
particular situation.
Thanks for any help that can be offered.
I have created a form with two unbound combo boxes. One allows the user to
select a code that represents a type of risk and the other allows the user to
select a code that represents a location. I am building a query that
includes the unbound combo boxes as selection criteria.
The user must select a risk type but need not necessarily select a location
code. If they select only a risk type and no location code I want the query
to return all records with the selected risk type and a null location value.
(Risk type is always populated whereas location is optional). If the use
selects a risk type and location code then I want the query to return records
where the risk type and location value match the user's selections.
I find that when I insert [Forms]![frmRegisterSearch]![comboLocation] in the
query criteria all works well if a non-null value is selected in the location
combo control, but if the combo control is left blank, the query does not
return any values.
I have tried inserting code like:
IIf(IsNull([Forms]![frmRegisterSearch]![comboLocation]),Null,[Forms]![frmRegisterSearch]![comboLocation]) but this does not work.
The SQL View of my current code is:
SELECT tblRegister.RegID, tblRegister.Type, tblRegister.Locn,
tblRegister.Manufacturer, tblRegister.Model, tblRegister.Archived
FROM tblRegister
WHERE (((tblRegister.Type)=[Forms]![frmRegisterSearch]![comboRiskType1]) AND
((tblRegister.Locn)=IIf(IsNull([Forms]![frmRegisterSearch]![comboLocation]),Null,[Forms]![frmRegisterSearch]![comboLocation])));
I realise my question is very similar to other questions on this site but I
just don't seem to be able to grasp how the other replies apply to my
particular situation.
Thanks for any help that can be offered.