IIF to do NOTHING if false.

Posted on 2004-11-16
Last Modified: 2012-06-27
this is pretty simple, or so I thought... I have a 2 text boxes with the following control source

=IIF([Month]='10/1/2003',[SumOfYTD Life])

=IIF([Month]='10/1/2004',[SumOfYTD Life])

I have 2 records in the report. One record has a date of 10/1/2003 the other 10/1/2004.

All I want to do is to have it evaluate and then set the boxes to the value as outlined in the IIF. The problem is that when it evaluates the expression for the second record, it finds it false and wipes out the value from the first record.

Is there any way to have the IIF do NOTHING if FALSE.....Absolutely nothing....I don't want the value to change. I will use the value later.

I have tried everything....I even tried SWITCH([Month]='10/1/2003',[SumOfYTD Life]).....It still evaluated and changed the value of the box.

please HELPPPP ME....
Question by:mflatford
    LVL 7

    Expert Comment

    IIf(expr, truepart, falsepart)

    =IIF([Month]='10/1/2004',[SumOfYTD Life],[Month])


    Author Comment

    Good try... Not the right answer..... I don't want ANYTHING in the field except for the record that has the date 10/1/2004....

    With the above, it would give my box the value of [Month] if false. I want it to do NOTHING if false... in other words, do not change the value. leave it as is...I don't want it null... I don't want a zero, I want it whatever value it was before the expression was evaluated. Therefore left UNCHANGED if false.... only change it if the expression is true.
    LVL 6

    Accepted Solution

    If I understand your problem correctly.. You want a textbox to change if it meets a certain criteria, but if it doesn't meet that criteria, you want it be [SumOfYTD] in the previous record.  To do this, we'll have to keep track of what your textbox *used* to be before you moved to the next (or previous) record.

    Lets just deal with your first textbox for the moment to keep things simpler.  In this example, I call the first textbox: txtStatus.
    1)Create another textbox called txtPrevStatus which is to be an unbound (nothing in the control source), hidden textbox.
    2)Change the control source of txtStatus to:  =getStatus()
    3)Insert the following code into the module code for this form:

    Private Function getStatus()
        If [Month] = '10/1/2003' Then
            txtPrevStatus.Value = [SumOfYTD]
        End If
        getStatus = txtPrevStatus.Value
    End Function

    4)All we need to figure out now is what do you want the value of txtStatus to be if the first record (when the form loads) doesn't match the criteria.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
    Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
    In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
    With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

    737 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

    18 Experts available now in Live!

    Get 1:1 Help Now