Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2016
    Posts
    29
    Provided Answers: 1

    Unanswered: Nesting an If within another If's condition statement

    Hi everyone,

    This isn't a must, as I can do this the long-winded way, but is it possible/has anyone tried nesting an If statement within the condition of another If Statement in Access? I'm essentially trying to do something like:

    If (If Gender = Male Then // Age_x// Else // Age_y End If) < Age_z Then
    a
    Else
    b
    End If

    So far, I just get a compile error message (expected: expression) every time I try to run nested If statements.. If anyone has any suggestions I'd appreciate it, thanks

  2. #2
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,482
    Provided Answers: 11
    That make it hard to read

    have you every use "if and only if"

    Bla = iif(con,true,false) like the Excel =if()

    other thing you could do is create true/false function
    Last edited by myle; 12-06-16 at 12:59. Reason: Spelling
    hope this help

    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.
    DONT WORRY ABOUT THOSE WHO TALK BEHIND YOUR BACK
    THEY'RE BEHIND YOU FOR A REASON

  3. #3
    Join Date
    Nov 2016
    Posts
    29
    Provided Answers: 1
    Thanks Stephan, I haven't tried IIf yet, it didn't seem to be useful for this, but maybe I discounted it too early. I'll give it a go tomorrow (wrapping up for the day now) and let you know. I can do it by writing something like:

    If Gender = Male Then
    If Age_x < Age_z Then
    a
    Else
    b
    End If
    Else
    If Age_y < Age_z Then
    etc.

    I was just looking for a more elegant/efficient solution which allowed me to decide which Age (x or y) to compare to Age_z in the first If statement. I'll give the IIf function a go tomorrow and let you know if it works as you anticipate. Thanks for helping

Posting Permissions

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