Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Posts
    361

    Unanswered: multiple if statement

    I want to write a multiple if statement but I don't know how. THis is what I have so far.

    2001: IIf([Model #]="955687","46%","Wrong")

    Right now if the model # is 955687 the text box shows 46%. If not it shows wrong.

    what I need to add is a few more model #'s. Like if model number is 955889 so on an so on. I just need to know the format.

    Thanks

  2. #2
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Smile Re: multiple if statement

    Originally posted by tjarvas
    I want to write a multiple if statement but I don't know how. THis is what I have so far.

    2001: IIf([Model #]="955687","46%","Wrong")

    Right now if the model # is 955687 the text box shows 46%. If not it shows wrong.

    what I need to add is a few more model #'s. Like if model number is 955889 so on an so on. I just need to know the format.

    Thanks
    What you need is the Switch function. Here's the help topic. See if it's not what you want.

    Switch Function


    Evaluates a list of expressions and returns a Variant value or an expression associated with the first expression in the list that is True.

    Syntax

    Switch(expr-1, value-1[, expr-2, value-2 … [, expr-n,value-n]])

    The Switch function syntax has these parts:

    Part Description
    expr Required. Variant expression you want to evaluate.
    value Required. Value or expression to be returned if the corresponding expression is True.



    Remarks

    The Switch function argument list consists of pairs of expressions and values. The expressions are evaluated from left to right, and the value associated with the first expression to evaluate to True is returned. If the parts aren't properly paired, a run-time error occurs. For example, if expr-1 is True, Switch returns value-1. If expr-1 is False, but expr-2 is True, Switch returns value-2, and so on.

    Switch returns a Null value if:

    None of the expressions is True.


    The first True expression has a corresponding value that is Null.
    Switch evaluates all of the expressions, even though it returns only one of them. For this reason, you should watch for undesirable side effects. For example, if the evaluation of any expression results in a division by zero error, an error occurs.
    Gregg


    DAO, ADO, SQL, Automation and anything else I can pick up.

  3. #3
    Join Date
    Apr 2004
    Location
    UK
    Posts
    4

    Re: multiple if statement

    You can just keep nesting the IIF statements if you want like this

    2001: IIf([Model #]="955687","46%",(IIF([Model #]="954334","54%","Wrong"))

    or you could use the Select Case statment the syntax is below.

    Select Case Number ' Evaluate Number.
    Case 1 To 5 ' Number between 1 and 5, inclusive.
    Debug.Print "Between 1 and 5"
    ' The following is the only Case clause that evaluates to True.
    Case 6, 7, 8 ' Number between 6 and 8.
    Debug.Print "Between 6 and 8"
    Case 9 To 10 ' Number is 9 or 10.
    Debug.Print "Greater than 8"
    Case Else ' Other values.
    Debug.Print "Not between 1 and 10"
    End Select

  4. #4
    Join Date
    Mar 2004
    Posts
    361
    2001: IIf([Model #]="986310S","43%",(IIF([Model#]="986310T","41%",(IIF([Model #]="996110S","46%",(IIF([Model #]="996110T","44%",(IIF([Model #]=”996310S”,"46%",(IIF([Model #]=“996310T”,"44%",(IIF([Model #]=”996410S”,"47%",(IIF([Model#]=”996410T”,"44%",(IIF([Model #]=”996610S”,"47%",(IIF([Model #]=”996610T”,"45%",”Wrong")))))))

    I think this might be too long. It gives me an error or the expression us too complex. Any ideas on what to do?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •