473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to show all values in a query iif criteria?

176 100+
Hello forum!

I have this question:

I have a query with a column that uses this criteria:

Expand|Select|Wrap|Line Numbers
  1. (IIfCustomerType()<>3,fCustomerType())
where fCustomerType() is a function result. But this criteria isn't enough because I also need a proper else condition that will show all the results. How do I write it?... I tried:
Expand|Select|Wrap|Line Numbers
  1. IIf(fCustomerType()<>3,fCustomerType(), Like"*")
, but it doesn't work

Thank you.
Jan 7 '08 #1
15 32394
Megalog
378 Expert 256MB
I'm also interested in a good answer to this, since I came upon the same problem a few days ago. I had an IIF statement in a query Criteria field, and it just wouldnt work no matter which way I arranged it. After a few hours of messing around with it, I ended up re-working my form to get around the query.
Jan 7 '08 #2
jaxjagfan
254 Expert 100+
Hello forum!

I have this question:

I have a query with a column that uses this criteria:

Expand|Select|Wrap|Line Numbers
  1. (IIfCustomerType()<>3,fCustomerType())
where fCustomerType() is a function result. But this criteria isn't enough because I also need a proper else condition that will show all the results. How do I write it?... I tried:
Expand|Select|Wrap|Line Numbers
  1. IIf(fCustomerType()<>3,fCustomerType(), Like"*")
, but it doesn't work

Thank you.
You need to replace the "Like *" with a function that returns results not the criteria of the function. If fCustomerType() returns a value if customer is "<>3" then you need a similar function to return a value when customer "=3".

Look at the fCustomerType() function and possibly create a 2nd one based on the 1st one or post it here for us to see. Can't be more definitive with more info.

IE - IIf(fCustomerType()<>3,fCustomerType(),fCustomerTy pe3())
Jan 7 '08 #3
Michael R
176 100+
You need to replace the "Like *" with a function that returns results not the criteria of the function. If fCustomerType() returns a value if customer is "<>3" then you need a similar function to return a value when customer "=3".

Look at the fCustomerType() function and possibly create a 2nd one based on the 1st one or post it here for us to see. Can't be more definitive with more info.

IE - IIf(fCustomerType()<>3,fCustomerType(),fCustomerTy pe3())

Thanks.

In my application, If fCustomerType()=1 then the query should show only the records with '1' values, if fCustomerType()=2 it should show only the records with '2' values, if fCustomerType()=3 it should show all records.

By what value of fCustomerType3() should I represent all values?
Jan 7 '08 #4
jaxjagfan
254 Expert 100+
Thanks.

In my application, If fCustomerType()=1 then the query should show only the records with '1' values, if fCustomerType()=2 it should show only the records with '2' values, if fCustomerType()=3 it should show all records.

By what value of fCustomerType3() should I represent all values?
If I am reading you reply correctly, you are not looking for the "false" side of an "IIF" function. What you need is a "WHERE" clause.

Select tblCustomers.* From tblCustomers WHERE CustomerType = [Forms]![YourFormName].[YourInputControl]

What are you trying to accomplish? Are you displaying the data in a report or selecting data for data entry? How are you controlling what CustomerType is selected - ComboBox, TextBox, etc.

The IIF whould normally be used if you were calculating or doing something different for each or a particular CustomerType. IE - Tax:IIf(customertype=3,0, taxrate*amount) This would imply all type 3 were tax-exempt and tax all others.
Jan 7 '08 #5
Michael R
176 100+
Select tblCustomers.* From tblCustomers WHERE CustomerType = [Forms]![YourFormName].[YourInputControl]

What are you trying to accomplish? Are you displaying the data in a report or selecting data for data entry? How are you controlling what CustomerType is selected - ComboBox, TextBox, etc.
The [CustomerType] values I have in tblCustomers are either 1,2,11 or NULL.

I want to write a query that selects either:

1. Only records with [CustomerType] value 1.
2. Only records with [CustomerType] value 2.
3. All the records availible.
and all this depending on the [Forms]![MyForm]![MyInputControl] which can be 1,2 or 3

I successfully acomplish selecting records with [CustomerType] value 1 or [CustomerType] value 2 with your query, but I can't get to select all records availible.

Regards.
Jan 8 '08 #6
FishVal
2,653 Expert 2GB
Hi, Michael.

Sounds to be trivial.

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM [YourTable] WHERE [CustomerType]=[Forms]![MyForm]![MyInputControl] OR IsNull([Forms]![MyForm]![MyInputControl]);
  2.  
Regards,
Fish
Jan 8 '08 #7
jaxjagfan
254 Expert 100+
Hi, Michael.

Sounds to be trivial.

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM [YourTable] WHERE [CustomerType]=[Forms]![MyForm]![MyInputControl] OR IsNull([Forms]![MyForm]![MyInputControl]);
  2.  
Regards,
Fish
If you are using 1, 2, and 3 as choices and the possible return values are 1, 2, and ALL.

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL as String
  2. Dim vCustType
  3. vCusttype = Me.MyInputControl
  4. If vCustType < 3 Then
  5. strSQL = "SELECT * FROM [YourTable] WHERE [CustomerType]=" & vCustType & ";"
  6. Else strSQL = "SELECT * FROM [YourTable]"
  7. End if
  8. Docmd.RunSQL strSQL
In essence it is 2 different queries where one looks for customertype 1 or 2 and the other pulls all records regardless of customertype. If you want all but 1 or 2 when you select 3 then change Fish's reply :

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM [YourTable] WHERE [CustomerType]=[Forms]![MyForm]![MyInputControl] OR Not In (1,2);
Jan 8 '08 #8
FishVal
2,653 Expert 2GB
If you want all but 1 or 2 when you select 3 then change Fish's reply :

SELECT * FROM [YourTable] WHERE [CustomerType]=[Forms]![MyForm]![MyInputControl] OR Not In (1,2);
Actually, if so, I would use
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM [YourTable] WHERE [CustomerType]=[Forms]![MyForm]![MyInputControl] OR [Forms]![MyForm]![MyInputControl]=3;
  2.  
But it seems me more intuitive to fetch all records if no filter is specified in [Forms]![MyForm]![MyInputControl] ([Forms]![MyForm]![MyInputControl] is Null).

Regards,
Fish
Jan 8 '08 #9
Michael R
176 100+
Thanks both of you.

Why does actually
Expand|Select|Wrap|Line Numbers
  1. OR [Forms]![MyForm]![MyInputControl]=3;
allows all the records to show when MyInputControl = 3?
Jan 8 '08 #10
Michael R
176 100+
In other words, can you explain why exactly this query works?
I changed * with Column1 for the convenience of the my question.

I get this part:
Expand|Select|Wrap|Line Numbers
  1. SELECT [Column1] FROM [YourTable] WHERE [CustomerType]=[Forms]![MyForm]![MyInputControl]
I select records where customertype has a specific value


Expand|Select|Wrap|Line Numbers
  1.  OR [Forms]![MyForm]![MyInputControl]=3;
Or where MyInputControl = 3. But why does it selects all the records?
Jan 8 '08 #11
jaxjagfan
254 Expert 100+
In other words, can you explain why exactly this query works?
I changed * with Column1 for the convenience of the my question.

I get this part:
Expand|Select|Wrap|Line Numbers
  1. SELECT [Column1] FROM [YourTable] WHERE [CustomerType]=[Forms]![MyForm]![MyInputControl]
I select records where customertype has a specific value


Expand|Select|Wrap|Line Numbers
  1.  OR [Forms]![MyForm]![MyInputControl]=3;
Or where MyInputControl = 3. But why does it selects all the records?
Because the WHERE clause is not looking at CustomerType anymore - it is looking for a value of 3 in MyInputControl and selecting all.
Jan 8 '08 #12
FishVal
2,653 Expert 2GB
In other words, can you explain why exactly this query works?
I changed * with Column1 for the convenience of the my question.

I get this part:
Expand|Select|Wrap|Line Numbers
  1. SELECT [Column1] FROM [YourTable] WHERE [CustomerType]=[Forms]![MyForm]![MyInputControl]
I select records where customertype has a specific value


Expand|Select|Wrap|Line Numbers
  1.  OR [Forms]![MyForm]![MyInputControl]=3;
Or where MyInputControl = 3. But why does it selects all the records?
Just would like to rephrase jaxjagfan's answer.

All you've entered in WHERE clause of SQL expression is being evaluated as a boolean expression in context of a record being fetched. If the expression evaluates to True, then the record is fetched, otherwise it is omitted.

So you have a simple boolean equation
Expand|Select|Wrap|Line Numbers
  1. [CustomerType]=[Forms]![MyForm]![MyInputControl] OR [Forms]![MyForm]![MyInputControl]=3
  2.  
Two boolean expressions joined by boolean operator OR. If either of them is True, then the whole expression is True. The first expression is record dependant - it may be False, True or Null for a particular record in the table. The second is record independant - it is being evaluated once for all records.
It is obvious that if the second expression is True then the whole expression will be True for all records:
Expand|Select|Wrap|Line Numbers
  1. True OR True = True
  2. False OR True = True
  3. Null OR True = True
on the other hand if the second expression is False then the whole expression will be:
Expand|Select|Wrap|Line Numbers
  1. True OR False = True
  2. False OR False = False
  3. Null OR False = Null 
Hope this makes a sense.

Regards,
Fish
Jan 8 '08 #13
Michael R
176 100+
Yes, I understand now it is possible to write a record independent expressions, but expressions that still makes sense to access query, such as access function.

Thanks guys for you help and explanation.
Regards.
Jan 9 '08 #14
Actually, I seem to find the trick:
simply change your expression
Expand|Select|Wrap|Line Numbers
  1. IIf(fCustomerType()<>3,fCustomerType(), Like"*")
as:
Expand|Select|Wrap|Line Numbers
  1. like IIf(fCustomerType()<>3,fCustomerType(), "*")
you will see what your want!
Jan 15 '13 #15
HouseHandler
1 Bit
@imahhua
Thank you imahhua

USE THE LIKE before the IIf statement. Like this.

Like IIf([Forms]![FormName]![FraFilter]=2,[Forms]![FormName]![txtNumber],"*")
Aug 3 '21 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: keliie | last post by:
Hello Just a quick question that I've spent a few hours trying to solve with no luck (although one would think this should be fairly easy). I have a form with a subform. The subform is based...
3
by: stevecat | last post by:
Hi there, I have created a form, "search" and a query "search_product". The query returns the product information based upon the criteria for three of the fields, author, title or isbn. The field...
4
waynetheengineer
by: waynetheengineer | last post by:
Hi, I was wondering if anyone had any suggestions on my database: I have a form that accepts user input into a single text box. When the OK button is hit, a query should search for all records...
3
by: ericargent | last post by:
Hi I'm using Acces 2003 I have Query where the several parameters for the criteria are supplied from a form. One parameter source is a combo box. What I am trying to do is if: An item is...
4
by: candide_sh | last post by:
Hi, I have a combobox cbosaSAK_FKEY with these values: 1 2 3 The query criteria has to be changed into: 1 =1
6
craigfr
by: craigfr | last post by:
I am making a graph comparing last year's defect data with YTD defect data. Our fiscal year starts Nov.1 and ends Oct.31. To get the YTD, I started used a simple date serial criteria: Between...
3
by: sfrvn | last post by:
I have searched high and low and cannot find an answer to my problem. So now I turn to the collective genius of this newsgroup. Over-simplified examples This query criteria for field works:...
2
by: NicholasSerpentine | last post by:
Hi folks....I have been checking out this group and have found help and solutions to everything I have needed up to this point. I have created a report based on a Query to show me certain activity...
4
by: tbeers | last post by:
Is there a method to pass along a criteria argument directly to the query criteria rather than through filtering a form or report? In other words, I would like to click a "print" button and in the...
8
by: limperger | last post by:
Hello everyone! First and foremost, my apologies for the title of the post. It is not very clarifying of what the problem is about, but I didn't know how to put it... My problem is as follows: I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.