# Thread: Nesting an If within another If's condition statement

1. Registered User
Join Date
Nov 2016
Posts
29

## 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. (Making Your Life Easy)
Join Date
Feb 2004
Location
New Zealand
Posts
1,482
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

3. Registered User
Join Date
Nov 2016
Posts
29
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
•