Criteria in Query for listbox rowsource

Below is a query i am trying to use as the row source for a list box on my form. In the criteria there is an iif statement. The false part of the iif statement works. But the true part does not.

what i have on my form is an option group which contains three radio buttons.

The choices to the user are:

0 = All
1 = Printer Type 1
2 = Printer Type 2

if the user selects the first option button, i want the query to return the records for both printer type 1 and printer type 2.

Please help me with this so that it can work the way i need to to.

Thanks...

SELECT Printers.ID, Printers.PartNumber, Printers.Description, Printers.ListPrice, Printers.IDTCost, Printers.LastUpdate
FROM Printers
WHERE (((Printers.Type)=IIf([Forms]![Printers].[printerType].[value]=0,([Printers].[Type])=1 AND ([Printers].[Type])=2,[Forms]![printers].[printerType].[value])));
BasicfarmerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

als315Commented:
Can you have Printers.Type value other then 1 or 2?
If can't, you can simplify your WHERE:
WHERE (IIF([Forms]![Printers].[printerType]=0, True, Printers.Type = [Forms]![printers].[printerType]))
0
BasicfarmerAuthor Commented:
I only have types 1 and 2. I dont know how to make it display all printer types.
0
als315Commented:
Try to change where as suggested above
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

BasicfarmerAuthor Commented:
It will not return any records as there are no records in the table with a type of 0.
0
als315Commented:
If [Forms]![Printers].[printerType] = 0 it will return all values, because it this case IIF will return True
0
Jeffrey CoachmanMIS LiasonCommented:
So these are choices are in an Option Group?
How many PrinterTypes are there?
If only those two, then use code like this:

Dim strSQL as string
strSQL ="SELECT Printers.ID, Printers.PartNumber, Printers.Description, Printers.ListPrice, Printers.IDTCost, Printers.LastUpdate
FROM Printers"
If me.YourFrame=0 then
    strSQL =strSQL
ElseIf me.YourFrame=1 then
    strSQL=strSQL & " WHERE Printers.Type=1"
ElseIf me.YourFrame=2 then
    strSQL=strSQL & " WHERE Printers.Type=2"
end if



If there are more than two Printertypes, use code like this:
Dim strSQL as string
strSQL ="SELECT Printers.ID, Printers.PartNumber, Printers.Description, Printers.ListPrice, Printers.IDTCost, Printers.LastUpdate
FROM Printers"
If me.YourFrame=0 then
    strSQL =strSQL  & "  WHERE Printers.Type=1 AND Printers.Type=2"
ElseIf me.YourFrame=1 then
    strSQL=strSQL & " WHERE Printers.Type=1"
ElseIf me.YourFrame=2 then
    strSQL=strSQL & " WHERE Printers.Type=2"
end if

(I'm am not sure what you IIF's are doing there, but generally speaking, the code I posted should work...)

JeffCoachman
0
BasicfarmerAuthor Commented:
OK let me rework this a bit...
0
BasicfarmerAuthor Commented:
Ok, I am convinced that it does not like the AND statement. When i click the radio button for "All" which has a value of 0, nothing is returned. When i click on type 1 or type 2 they both work as they should.

Private Sub Form_Load()

    Dim SQL As String
   
    SQL = "SELECT ID,PartNumber,Description,ListPrice,IDTCost,LastUpdate " & _
          "FROM Printers "
   
    List0.RowSource = SQL
   
End Sub

Private Sub printerType_Click()

    Dim SQL As String
   
    SQL = "SELECT ID,PartNumber,Description,ListPrice,IDTCost,LastUpdate " & _
          "FROM Printers "
         
    If printerType.Value = 0 Then
       
        SQL = SQL & "WHERE Type = 1 and Type = 2"
   
    ElseIf printerType.Value = 1 Then
       
        SQL = SQL & "WHERE Type = 1"
       
    ElseIf printerType.Value = 2 Then
   
        SQL = SQL & "WHERE Type = 2"
       
    End If
   
    List0.RowSource = SQL
   
    List0.Requery

End Sub
0
Jeffrey CoachmanMIS LiasonCommented:
Try:
"  WHERE Type=1 AND Type=2"
(Note the space character before the WHERE)

To be sure, always do this before running any SQL to check for syntax errors:
    msgbox SQL
0
Jeffrey CoachmanMIS LiasonCommented:
<I am convinced that it does not like the AND statement.>
LOL

Change it to: OR

;-)
0
BasicfarmerAuthor Commented:
I put the space character after "FROM Printers "
0
Jeffrey CoachmanMIS LiasonCommented:
sb:
SQL = SQL & "WHERE Type = 1 OR Type = 2"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BasicfarmerAuthor Commented:
THAT DID IT!!!!
0
BasicfarmerAuthor Commented:
Thanks for the grate help...
0
Jeffrey CoachmanMIS LiasonCommented:
...that was funny how we both missed that......
;-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.