Hello forum!
I have this question:
I have a query with a column that uses this criteria: - (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: - IIf(fCustomerType()<>3,fCustomerType(), Like"*")
, but it doesn't work
Thank you.
15 32394
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.
Hello forum!
I have this question:
I have a query with a column that uses this criteria: - (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: - 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())
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?
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.
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.
Hi, Michael.
Sounds to be trivial. -
SELECT * FROM [YourTable] WHERE [CustomerType]=[Forms]![MyForm]![MyInputControl] OR IsNull([Forms]![MyForm]![MyInputControl]);
-
Regards,
Fish
Hi, Michael.
Sounds to be trivial. -
SELECT * FROM [YourTable] WHERE [CustomerType]=[Forms]![MyForm]![MyInputControl] OR IsNull([Forms]![MyForm]![MyInputControl]);
-
Regards,
Fish
If you are using 1, 2, and 3 as choices and the possible return values are 1, 2, and ALL. - Dim strSQL as String
-
Dim vCustType
-
vCusttype = Me.MyInputControl
-
If vCustType < 3 Then
-
strSQL = "SELECT * FROM [YourTable] WHERE [CustomerType]=" & vCustType & ";"
-
Else strSQL = "SELECT * FROM [YourTable]"
-
End if
-
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 : - SELECT * FROM [YourTable] WHERE [CustomerType]=[Forms]![MyForm]![MyInputControl] OR Not In (1,2);
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 -
SELECT * FROM [YourTable] WHERE [CustomerType]=[Forms]![MyForm]![MyInputControl] OR [Forms]![MyForm]![MyInputControl]=3;
-
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
Thanks both of you.
Why does actually - OR [Forms]![MyForm]![MyInputControl]=3;
allows all the records to show when MyInputControl = 3?
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: - SELECT [Column1] FROM [YourTable] WHERE [CustomerType]=[Forms]![MyForm]![MyInputControl]
I select records where customertype has a specific value - OR [Forms]![MyForm]![MyInputControl]=3;
Or where MyInputControl = 3. But why does it selects all the records?
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: - SELECT [Column1] FROM [YourTable] WHERE [CustomerType]=[Forms]![MyForm]![MyInputControl]
I select records where customertype has a specific value - 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.
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: - SELECT [Column1] FROM [YourTable] WHERE [CustomerType]=[Forms]![MyForm]![MyInputControl]
I select records where customertype has a specific value - 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 -
[CustomerType]=[Forms]![MyForm]![MyInputControl] OR [Forms]![MyForm]![MyInputControl]=3
-
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: -
True OR True = True
-
False OR True = True
-
Null OR True = True
on the other hand if the second expression is False then the whole expression will be: -
True OR False = True
-
False OR False = False
-
Null OR False = Null
Hope this makes a sense.
Regards,
Fish
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.
Actually, I seem to find the trick:
simply change your expression - IIf(fCustomerType()<>3,fCustomerType(), Like"*")
as: - like IIf(fCustomerType()<>3,fCustomerType(), "*")
you will see what your want!
@imahhua
Thank you imahhua
USE THE LIKE before the IIf statement. Like this.
Like IIf([Forms]![FormName]![FraFilter]=2,[Forms]![FormName]![txtNumber],"*")
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
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:...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
| |