If...ElseIf...Then Statement

G

Guest

Having a problem getting an If...ElseIf...Then statement to work. I have:

If ([Control 2] >399) And ([Control 2] < 5001) Then
Do This

ElseIf ([Control 1] = "xxx") And ([Control 2] > 399) And ([Control 2] <
5001) Then
Do This

Else
Do This

End If
 
B

Bill Edwards

Using that logic the do this stuff code for:

ElseIf ([Control 1] = "xxx") And ([Control 2] > 399) And ([Control 2] <
5001)

will never execute
 
F

fredg

Having a problem getting an If...ElseIf...Then statement to work. I have:

If ([Control 2] >399) And ([Control 2] < 5001) Then
Do This

ElseIf ([Control 1] = "xxx") And ([Control 2] > 399) And ([Control 2] <
5001) Then
Do This

Else
Do This

End If


You also need to check if [Control] is not "xxx", otherwise you will
never get to the ElseIf.
Also notice the different parenthesis placement.

If [Control 1] <> "xxx" And ([Control 2] > 399 And [Control 2] <
5001) Then
Do this thing
ElseIf [Control 1] = "xxx" And ([Control 2] > 399 And [Control 2] <
5001) Then
Do this other thing
Else
Do that
End IF
 
G

George Nicholson

If ([Control 2] >399) And ([Control 2] < 5001) Then
If ([Control 1] = "xxx") then
'What was your 2nd "Do This"
Else
'What was your 1st "Do This"
End If
Else
Do This
End If

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top