If based on the outcome of 2 fields

Posted on 2011-04-21
Last Modified: 2012-05-11
I am trying to create an access 2007 report. This is based on a cross tab query. I use a SQL statement of the basis for my crosstab and I want a value returned to be based on the combined vakue of two fields. the IF statement that I need to represent is something like the below.

IF field1 is one of 5 values and field2 = 0 then
IF field1 is one of 2 values and field2 = 1 then

What is the best way to do this?

Question by:JayceW
    LVL 22

    Accepted Solution

    You can use this expression in the report or the query:
    IIf([Field1] In ('a','b','c','d','e') And [Field2]=0,"
       IIf([Field1] In ('f','g') And [Field2]=1,

    Open in new window

    If field1 is a number use numbers for the values and don't use the single quotes.
    LVL 119

    Assisted Solution

    by:Rey Obrero
    try this as a column in the query

    iif([f1] in(1,2,3,4,5) and [f2]=0,"orange",iif([f1] in (1,2) and [f2]=1,"brown","black"))

    Author Closing Comment

    Thanks for the speedy respose guys.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
    I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
    What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now