nested if statements (1 Viewer)

jlabre01

Registered User.
Local time
Today, 08:22
Joined
May 26, 2008
Messages
62
Hi,

I'm working on designing a special invoicing form for my business and in order to do so i need to check a couple different things when it looks for the price, I just wanted to know if nested if statements are possible or not?

jlabre01
 
Local time
Today, 07:22
Joined
Mar 4, 2008
Messages
3,856
Yes, nested if statements are possible:

Code:
if condition1 then
 if condition2 then
  dostuff
 else
  dootherstuff
 end if 'condition 2
else
 if condition3 then
  doevenmorestuff
 elseif condition4 then
  doadditionalstuff
 else
  doadditionalstuffevenmore
 end if 'condition3
end if 'condition1

You can go very deep into the nest. How deep? I don't know...so deep I've never hit the limit.
 

jlabre01

Registered User.
Local time
Today, 08:22
Joined
May 26, 2008
Messages
62
ok but how do i do that as a control source for a text box?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:22
Joined
Feb 19, 2002
Messages
43,592
You would use the IIf() function. This function allows nesting but it rapidly becomes impossible for people (you included) to understand. Better to add VBA to some event so you can use the nested If structure similar to what george posted. You should also look into Choose() as a possible alternative to the IIf() if your choices are simple enough. And if you are testing the same field over and over again, it is better to use a Case statement than a nested if.
 

Users who are viewing this thread

Top Bottom