A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

"Not Equal" inside an IIf statement



 
 
Thread Tools Display Modes
  #1  
Old November 9th, 2007, 09:25 PM posted to microsoft.public.access.queries
jas580
external usenet poster
 
Posts: 40
Default "Not Equal" inside an IIf statement

Hi,
I have the following expression in the criteria of [Security Type].[Security
Type ID] field in a query:

IIf([Forms]![frmLookup]![TypeSelect]=1,[Security Type].[Security Type
ID],IIf([Forms]![frmLookup]![TypeSelect]=2,3,3))

[TypeSelect] is a combo box on a form with the following 3 options:
1, All Securities
2, CV
3, ST

[Security Type ID] is from a table with numbers 1-50.

When I run the query with option 1 or 2 selected, it works fine. But it
returns nothing when option 3 is selected (the false piece of the 2nd IIf
statement). However, if I just use 3 in the criteria by itself, the
correct records are returned. I can't figure out why it doesn't work while
inside the IIf statement. I don't get any errors, it just returns nothing.

Thanks in advance for the help!

-Jeff

  #2  
Old November 9th, 2007, 10:29 PM posted to microsoft.public.access.queries
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default "Not Equal" inside an IIf statement

Try putting quotes around it like this ---
IIf([Forms]![frmLookup]![TypeSelect]=1,[Security Type].[Security Type
ID],IIf([Forms]![frmLookup]![TypeSelect]=2,"3","3"))

--
KARL DEWEY
Build a little - Test a little


"jas580" wrote:

Hi,
I have the following expression in the criteria of [Security Type].[Security
Type ID] field in a query:

IIf([Forms]![frmLookup]![TypeSelect]=1,[Security Type].[Security Type
ID],IIf([Forms]![frmLookup]![TypeSelect]=2,3,3))

[TypeSelect] is a combo box on a form with the following 3 options:
1, All Securities
2, CV
3, ST

[Security Type ID] is from a table with numbers 1-50.

When I run the query with option 1 or 2 selected, it works fine. But it
returns nothing when option 3 is selected (the false piece of the 2nd IIf
statement). However, if I just use 3 in the criteria by itself, the
correct records are returned. I can't figure out why it doesn't work while
inside the IIf statement. I don't get any errors, it just returns nothing.

Thanks in advance for the help!

-Jeff

  #3  
Old November 9th, 2007, 10:50 PM posted to microsoft.public.access.queries
jas580
external usenet poster
 
Posts: 40
Default "Not Equal" inside an IIf statement

no luck. I got the error "the expression is too complicated to evaluate".

"KARL DEWEY" wrote:

Try putting quotes around it like this ---
IIf([Forms]![frmLookup]![TypeSelect]=1,[Security Type].[Security Type
ID],IIf([Forms]![frmLookup]![TypeSelect]=2,"3","3"))

--
KARL DEWEY
Build a little - Test a little


"jas580" wrote:

Hi,
I have the following expression in the criteria of [Security Type].[Security
Type ID] field in a query:

IIf([Forms]![frmLookup]![TypeSelect]=1,[Security Type].[Security Type
ID],IIf([Forms]![frmLookup]![TypeSelect]=2,3,3))

[TypeSelect] is a combo box on a form with the following 3 options:
1, All Securities
2, CV
3, ST

[Security Type ID] is from a table with numbers 1-50.

When I run the query with option 1 or 2 selected, it works fine. But it
returns nothing when option 3 is selected (the false piece of the 2nd IIf
statement). However, if I just use 3 in the criteria by itself, the
correct records are returned. I can't figure out why it doesn't work while
inside the IIf statement. I don't get any errors, it just returns nothing.

Thanks in advance for the help!

-Jeff

  #4  
Old November 9th, 2007, 10:50 PM posted to microsoft.public.access.queries
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default "Not Equal" inside an IIf statement

You can't use IIf statements to change the operator that's being used in a
criteria.

You'll need to use something like:

= [Security Type].[Security Type ID] AND [Forms]![frmLookup]![TypeSelect]=1

as the criteria on one line,

= 2 AND [Forms]![frmLookup]![TypeSelect]=2

as the criteria on a second line, and

3 AND [Forms]![frmLookup]![TypeSelect] NOT IN (1, 2)


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"jas580" wrote in message
...
Hi,
I have the following expression in the criteria of [Security
Type].[Security
Type ID] field in a query:

IIf([Forms]![frmLookup]![TypeSelect]=1,[Security Type].[Security Type
ID],IIf([Forms]![frmLookup]![TypeSelect]=2,3,3))

[TypeSelect] is a combo box on a form with the following 3 options:
1, All Securities
2, CV
3, ST

[Security Type ID] is from a table with numbers 1-50.

When I run the query with option 1 or 2 selected, it works fine. But it
returns nothing when option 3 is selected (the false piece of the 2nd IIf
statement). However, if I just use 3 in the criteria by itself, the
correct records are returned. I can't figure out why it doesn't work
while
inside the IIf statement. I don't get any errors, it just returns
nothing.

Thanks in advance for the help!

-Jeff



  #5  
Old November 9th, 2007, 11:32 PM posted to microsoft.public.access.queries
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default "Not Equal" inside an IIf statement

I did not read your post close enough.
What data is in the field that this criteria is selecting? Does it have 1,
2, & 3?
Or does it have AL, BT, CV, ST, etc.?
Or only 'All Securities', 'CV', & 'ST'.

--
KARL DEWEY
Build a little - Test a little


"jas580" wrote:

no luck. I got the error "the expression is too complicated to evaluate".

"KARL DEWEY" wrote:

Try putting quotes around it like this ---
IIf([Forms]![frmLookup]![TypeSelect]=1,[Security Type].[Security Type
ID],IIf([Forms]![frmLookup]![TypeSelect]=2,"3","3"))

--
KARL DEWEY
Build a little - Test a little


"jas580" wrote:

Hi,
I have the following expression in the criteria of [Security Type].[Security
Type ID] field in a query:

IIf([Forms]![frmLookup]![TypeSelect]=1,[Security Type].[Security Type
ID],IIf([Forms]![frmLookup]![TypeSelect]=2,3,3))

[TypeSelect] is a combo box on a form with the following 3 options:
1, All Securities
2, CV
3, ST

[Security Type ID] is from a table with numbers 1-50.

When I run the query with option 1 or 2 selected, it works fine. But it
returns nothing when option 3 is selected (the false piece of the 2nd IIf
statement). However, if I just use 3 in the criteria by itself, the
correct records are returned. I can't figure out why it doesn't work while
inside the IIf statement. I don't get any errors, it just returns nothing.

Thanks in advance for the help!

-Jeff

  #6  
Old November 10th, 2007, 12:36 PM posted to microsoft.public.access.queries
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default "Not Equal" inside an IIf statement

Karl: See my response. You cannot use an IIf statement to change the
comparison from = to .

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"KARL DEWEY" wrote in message
...
I did not read your post close enough.
What data is in the field that this criteria is selecting? Does it have
1,
2, & 3?
Or does it have AL, BT, CV, ST, etc.?
Or only 'All Securities', 'CV', & 'ST'.

--
KARL DEWEY
Build a little - Test a little


"jas580" wrote:

no luck. I got the error "the expression is too complicated to
evaluate".

"KARL DEWEY" wrote:

Try putting quotes around it like this ---
IIf([Forms]![frmLookup]![TypeSelect]=1,[Security Type].[Security Type
ID],IIf([Forms]![frmLookup]![TypeSelect]=2,"3","3"))

--
KARL DEWEY
Build a little - Test a little


"jas580" wrote:

Hi,
I have the following expression in the criteria of [Security
Type].[Security
Type ID] field in a query:

IIf([Forms]![frmLookup]![TypeSelect]=1,[Security Type].[Security Type
ID],IIf([Forms]![frmLookup]![TypeSelect]=2,3,3))

[TypeSelect] is a combo box on a form with the following 3 options:
1, All Securities
2, CV
3, ST

[Security Type ID] is from a table with numbers 1-50.

When I run the query with option 1 or 2 selected, it works fine. But
it
returns nothing when option 3 is selected (the false piece of the 2nd
IIf
statement). However, if I just use 3 in the criteria by itself,
the
correct records are returned. I can't figure out why it doesn't work
while
inside the IIf statement. I don't get any errors, it just returns
nothing.

Thanks in advance for the help!

-Jeff



  #7  
Old November 12th, 2007, 05:32 PM posted to microsoft.public.access.queries
jas580
external usenet poster
 
Posts: 40
Default "Not Equal" inside an IIf statement

Thank you for the help... I tried that and when I reopen the query to edit
it, the three criteria lines changed to:

[Security Type].[Security Type ID]
2
3

Everything else disappeared!

When I ran it, it came up with no results when user selects 1 or 2.
Selection 3 worked though, so I guess it's only recognizing the 3 criteria?
I believe I understand your recommendation conceptually, but every time I
try something different in the criteria, Access gets rid of everything I type
and leaves just a number, like what I mentioned above. Not sure what to try
now.

-Jeff


"Douglas J. Steele" wrote:

You can't use IIf statements to change the operator that's being used in a
criteria.

You'll need to use something like:

= [Security Type].[Security Type ID] AND [Forms]![frmLookup]![TypeSelect]=1

as the criteria on one line,

= 2 AND [Forms]![frmLookup]![TypeSelect]=2

as the criteria on a second line, and

3 AND [Forms]![frmLookup]![TypeSelect] NOT IN (1, 2)


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"jas580" wrote in message
...
Hi,
I have the following expression in the criteria of [Security
Type].[Security
Type ID] field in a query:

IIf([Forms]![frmLookup]![TypeSelect]=1,[Security Type].[Security Type
ID],IIf([Forms]![frmLookup]![TypeSelect]=2,3,3))

[TypeSelect] is a combo box on a form with the following 3 options:
1, All Securities
2, CV
3, ST

[Security Type ID] is from a table with numbers 1-50.

When I run the query with option 1 or 2 selected, it works fine. But it
returns nothing when option 3 is selected (the false piece of the 2nd IIf
statement). However, if I just use 3 in the criteria by itself, the
correct records are returned. I can't figure out why it doesn't work
while
inside the IIf statement. I don't get any errors, it just returns
nothing.

Thanks in advance for the help!

-Jeff




  #8  
Old November 12th, 2007, 05:44 PM posted to microsoft.public.access.queries
jas580
external usenet poster
 
Posts: 40
Default "Not Equal" inside an IIf statement

Hi Karl, thank you for the help...

The user is selecting option 1, 2 or 3 from drop down box [TypeSelect] (the
number is stored).

If 1 is selected, then return all records
If 2 is selected, then return all records where [Security Type ID]=3
If 3 is selected, then return all records where [Security Type ID]3

I understand from Douglas Steele's response that I can't use in IIf
statements inside a criteria.

Not sure what else to try at this point...

-Jeff





"KARL DEWEY" wrote:

I did not read your post close enough.
What data is in the field that this criteria is selecting? Does it have 1,
2, & 3?
Or does it have AL, BT, CV, ST, etc.?
Or only 'All Securities', 'CV', & 'ST'.

--
KARL DEWEY
Build a little - Test a little


"jas580" wrote:

no luck. I got the error "the expression is too complicated to evaluate".

"KARL DEWEY" wrote:

Try putting quotes around it like this ---
IIf([Forms]![frmLookup]![TypeSelect]=1,[Security Type].[Security Type
ID],IIf([Forms]![frmLookup]![TypeSelect]=2,"3","3"))

--
KARL DEWEY
Build a little - Test a little


"jas580" wrote:

Hi,
I have the following expression in the criteria of [Security Type].[Security
Type ID] field in a query:

IIf([Forms]![frmLookup]![TypeSelect]=1,[Security Type].[Security Type
ID],IIf([Forms]![frmLookup]![TypeSelect]=2,3,3))

[TypeSelect] is a combo box on a form with the following 3 options:
1, All Securities
2, CV
3, ST

[Security Type ID] is from a table with numbers 1-50.

When I run the query with option 1 or 2 selected, it works fine. But it
returns nothing when option 3 is selected (the false piece of the 2nd IIf
statement). However, if I just use 3 in the criteria by itself, the
correct records are returned. I can't figure out why it doesn't work while
inside the IIf statement. I don't get any errors, it just returns nothing.

Thanks in advance for the help!

-Jeff

  #9  
Old November 12th, 2007, 08:21 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default "Not Equal" inside an IIf statement

You might try the following. The speed may not be all that good, but it
will probably work

WHERE IIF([Forms]![frmLookup]![TypeSelect]=1,[Security Type].[Security Type
ID] Is Not Null,
IIf([Forms]![frmLookup]![TypeSelect]=2, [Security Type].[Security Type] = 3,
[Security Type].[Security Type] 3))


--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

"jas580" wrote in message
...
Hi Karl, thank you for the help...

The user is selecting option 1, 2 or 3 from drop down box [TypeSelect]
(the
number is stored).

If 1 is selected, then return all records
If 2 is selected, then return all records where [Security Type ID]=3
If 3 is selected, then return all records where [Security Type ID]3

I understand from Douglas Steele's response that I can't use in IIf
statements inside a criteria.

Not sure what else to try at this point...

-Jeff





"KARL DEWEY" wrote:

I did not read your post close enough.
What data is in the field that this criteria is selecting? Does it have
1,
2, & 3?
Or does it have AL, BT, CV, ST, etc.?
Or only 'All Securities', 'CV', & 'ST'.

--
KARL DEWEY
Build a little - Test a little


"jas580" wrote:

no luck. I got the error "the expression is too complicated to
evaluate".

"KARL DEWEY" wrote:

Try putting quotes around it like this ---
IIf([Forms]![frmLookup]![TypeSelect]=1,[Security Type].[Security Type
ID],IIf([Forms]![frmLookup]![TypeSelect]=2,"3","3"))

--
KARL DEWEY
Build a little - Test a little


"jas580" wrote:

Hi,
I have the following expression in the criteria of [Security
Type].[Security
Type ID] field in a query:

IIf([Forms]![frmLookup]![TypeSelect]=1,[Security Type].[Security
Type
ID],IIf([Forms]![frmLookup]![TypeSelect]=2,3,3))

[TypeSelect] is a combo box on a form with the following 3 options:
1, All Securities
2, CV
3, ST

[Security Type ID] is from a table with numbers 1-50.

When I run the query with option 1 or 2 selected, it works fine.
But it
returns nothing when option 3 is selected (the false piece of the
2nd IIf
statement). However, if I just use 3 in the criteria by itself,
the
correct records are returned. I can't figure out why it doesn't
work while
inside the IIf statement. I don't get any errors, it just returns
nothing.

Thanks in advance for the help!

-Jeff



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:42 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.