Results 1 to 7 of 7
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    If statement pseudo code (2003)

    I want to make the following calculation in an Access query for a calculation called Medical. If they have Medical and Vision, I want an X and If they have Medical and no Vision, I want and X.
    if ( Fa Total Contracts > 0 and Vision Total Contracts > 0 ) then ( 'X' ) else if ( Fa Total Contracts > 0 and Vision Total Contracts = 0 ) then ( 'X' ) else NULL . I am not sure about the syntax for a compound if statement. Thanks for your help.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: If statement pseudo code (2003)

    From your description, it would not seem to matter whether they have Vision or not - the result is the same in both cases. The outcome only depends on Medical, so try
    <code>
    IIf([Fa Total Contracts]>0,"X",Null)
    </code>
    Or am I completely off?

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: If statement pseudo code (2003)

    I figured out the syntax:
    Medical: IIf([contracts]>0 And [vision]>0,"X",IIf([contracts]>0 And [vision]=0,"X",Null))
    I also have another calculation similar to this to figure out the vision contracts
    VisionCon: IIf([Vision]>0 And [Contracts]>0,"X",IIf([Vision]>0 And [Contracts]=0,"X",Null))

    I renamed Fa total Contracts to "contracts" and Total Vision Contracts to "Vision".

    I want an "X" if they have both medical contracts and vision contract and an "X" if they have just Medical and no vision.
    Same for Vision.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: If statement pseudo code (2003)

    You're making it far too complicated. You can simplify the expressions to
    <code>
    Medical: IIf([contracts]>0,"X",Null)
    </code>
    and
    <code>
    VisionCon: IIf([Vision]>0,"X",Null)</code>

  5. #5
    Lounger
    Join Date
    Sep 2003
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: If statement pseudo code (2003)

    I want an X if Contracts > 0 and Vision = 0 also
    Same for Vision
    I want an X if Vision > 0 and Contracts = 0

    Wouldn't I be missing those Xs

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: If statement pseudo code (2003)

    > Wouldn't I be missing those Xs

    No - you want an "X" in the Medical column if Contracts is > 0, whether Vision is > 0 or = 0, so there is no need to include Vision in the expression for Medical.
    Similarly, you want an "X" in the VisionCon column if Vision is > 0, regardless of whether Contracts is > 0 or = 0, so there is no need to include Contracts in the expression for VisionCon.

    Have you actually tried the expressions I posted?

  7. #7
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: If statement pseudo code (2003)

    You were right. I tried what you said and I get the same results as when I used the other longer version.

Posting Permissions

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