Using an IIf statement to populate a combo box

G

Guest

Here is the SQL of my query:

SELECT ProjDetail.[Project Detail], ProjDetail.NeedPartNum
FROM ProjDetail
WHERE (((ProjDetail.NeedPartNum) Like IIf([Forms]![SavingsForm]![Part #]=""
Or [Forms]![SavingsForm]![Part #] Is Null,"No","*")));

I am trying to populate my Project Detail combo box with values from table
ProjDetail depending on what is entered to form field [Part #]. If the [Part
#] is null, then projects with a " NeedPartNum = No " should populate the
combo box, else all projects should be seen in the combo box.

I am using the SQL above for the RowSource of the Project Detail combo box
and tried to requery the [Part #] field after update. Currently only projects
with a "NeedPartNum = No" populate the project detail combo box regardless of
the Part # value.

Thanks for an ideas you might have..
 
G

George Nicholson

First thing I'd try would be to use IsNull() within your iif(), rather than
Is Null
(SQL likes Is Null but VBA likes IsNull(), and iif() is VBA):

IsNull([Forms]![SavingsForm]![Part #])

HTH,
 
J

John Spencer

Assumption:
NeedPartNum is a Yes/No (boolean) field.


SELECT ProjDetail.[Project Detail], ProjDetail.NeedPartNum
FROM ProjDetail
WHERE ProjDetail.NeedPartNum =
IIf([Forms]![SavingsForm]![Part #] Is Null,False,True) OR
Forms!SavingsForm![Part #] is Not Null
 
G

Guest

I tried your suggestion, but even when the [Part #] field is left blank in
the form, the query is not reading it as null.

George Nicholson said:
First thing I'd try would be to use IsNull() within your iif(), rather than
Is Null
(SQL likes Is Null but VBA likes IsNull(), and iif() is VBA):

IsNull([Forms]![SavingsForm]![Part #])

HTH,
--
George Nicholson

Remove 'Junk' from return address.


almb said:
Here is the SQL of my query:

SELECT ProjDetail.[Project Detail], ProjDetail.NeedPartNum
FROM ProjDetail
WHERE (((ProjDetail.NeedPartNum) Like IIf([Forms]![SavingsForm]![Part
#]=""
Or [Forms]![SavingsForm]![Part #] Is Null,"No","*")));

I am trying to populate my Project Detail combo box with values from table
ProjDetail depending on what is entered to form field [Part #]. If the
[Part
#] is null, then projects with a " NeedPartNum = No " should populate the
combo box, else all projects should be seen in the combo box.

I am using the SQL above for the RowSource of the Project Detail combo box
and tried to requery the [Part #] field after update. Currently only
projects
with a "NeedPartNum = No" populate the project detail combo box regardless
of
the Part # value.

Thanks for an ideas you might have..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top