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 » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Complex IF statement



 
 
Thread Tools Display Modes
  #1  
Old January 9th, 2008, 10:14 PM posted to microsoft.public.access.forms
PDLG
external usenet poster
 
Posts: 4
Default Complex IF statement

I have a database and for one of my reports, I need to have Access
evaluate a series of fields and then display the value of one of the
fields based on specific criteria and I can't figure out how.

Here's the scenario:

Look at Field A and if there is a value less than X in there, display
this value in Field Z; if there is a value of X in there, skip to
Field B. If Field B has a value less than X in there, display this
value in Field Z; if there is a value of X in there, skip to Field
C . . . and so on.

There are about 10 fields and I've tried using an IF statement but,
this is too convoluted or . . . I just don't know how to write it.

Help!
  #2  
Old January 9th, 2008, 10:21 PM posted to microsoft.public.access.forms
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default Complex IF statement

=IIf([FieldA] X, [FieldA], IIf([FieldB] X, [FieldB], IIf([FIeldC] X,
[FieldC], ..., IIf([FieldJ] X, [FieldJ], Null))))))))))

I THINK you can nest 10 IIf statements like that...

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


"PDLG" wrote in message
...
I have a database and for one of my reports, I need to have Access
evaluate a series of fields and then display the value of one of the
fields based on specific criteria and I can't figure out how.

Here's the scenario:

Look at Field A and if there is a value less than X in there, display
this value in Field Z; if there is a value of X in there, skip to
Field B. If Field B has a value less than X in there, display this
value in Field Z; if there is a value of X in there, skip to Field
C . . . and so on.

There are about 10 fields and I've tried using an IF statement but,
this is too convoluted or . . . I just don't know how to write it.

Help!



  #3  
Old January 10th, 2008, 12:12 AM posted to microsoft.public.access.forms
PDLG
external usenet poster
 
Posts: 4
Default Complex IF statement

On Jan 9, 2:21*pm, "Douglas J. Steele"
wrote:
=IIf([FieldA] X, [FieldA], IIf([FieldB] X, [FieldB], IIf([FIeldC] X,
[FieldC], ..., IIf([FieldJ] X, [FieldJ], Null))))))))))

I THINK you can nest 10 IIf statements like that...

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

"PDLG" wrote in message

...



I have a database and for one of my reports, I need to have Access
evaluate a series of fields and then display the value of one of the
fields based on specific criteria and I can't figure out how.


Here's the scenario:


Look at Field A and if there is a value less than X in there, display
this value in Field Z; if there is a value of X in there, skip to
Field B. If Field B has a value less than X in there, display this
value in Field Z; if there is a value of X in there, skip to Field
C . . . and so on.


There are about 10 fields and I've tried using an IF statement but,
this is too convoluted or . . . I just don't know how to write it.


Help!- Hide quoted text -


- Show quoted text -


Thanks, that was perfect. I guess I just wasn't being patient enough!!
  #4  
Old January 10th, 2008, 12:17 AM posted to microsoft.public.access.forms
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Complex IF statement

On Wed, 9 Jan 2008 14:14:00 -0800 (PST), PDLG wrote:

I have a database and for one of my reports, I need to have Access
evaluate a series of fields and then display the value of one of the
fields based on specific criteria and I can't figure out how.

Here's the scenario:

Look at Field A and if there is a value less than X in there, display
this value in Field Z; if there is a value of X in there, skip to
Field B. If Field B has a value less than X in there, display this
value in Field Z; if there is a value of X in there, skip to Field
C . . . and so on.

There are about 10 fields and I've tried using an IF statement but,
this is too convoluted or . . . I just don't know how to write it.

Help!


The Switch() function is prefect for this case. It takes an arbitrary number
of pairs of arguments; evaluates them left to right; and when it first
encounters a pair for which the first element is TRUE it returns the second of
the pair and quits:

Z: Switch([A] [X], [A], [b] [X], [b], [C] [X], [C], ..., True, "Nothing
qualified")

John W. Vinson [MVP]
 




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 06:25 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.