NESTED IF'S STATEMENT

adewale4favour

Registered User.
Local time
Yesterday, 20:05
Joined
Aug 9, 2019
Messages
58
Hi,
I have a project currently in my hand. Two variables are to be checked with If Statements. If the first set of conditions are true, then the code should stop executing, if the first condition is true, then it should proceed to check the second condition. If the second condition is verified, then another bunch of code can continue.

I keep getting a compiler error: "If without Else", and when I reverse the code, "I get Else without If error"

Below is the code, please help if you can

Private Sub Command49_Click()
On Error Resume Next

If Me.ROUTE.Value = "SILO" Then
If IsNull(DLookup("ATC_SILO", "ATC_SILOqry")) Then
MsgBox "The request is currently not available", "No ATC"
Cancel = True

Else

Me.ATC_NO = DLookup("ATC_SILO", "ATC_SILOqry")
DoCmd.Save
DoCmd.SetWarnings False
DoCmd.OpenQuery "qrydeleteupdatedSILO"
DoCmd.SetWarnings True
DoCmd.Close
DoCmd.OpenForm "ATC_UTILIZATION", acNormal

Many thanks in advance
 
Actually, what you DON'T have is an End If. So what is probably happening is that a later "IF" statement gets involved with your "dangling" IF and decides to complain at that time.
 
Many thanks, Doc_Man. But, the End If Code Block should usually come after the bunch of code is completed. That is included, yet the error persists.
 
No what Doc means is that for each If you start you need an End If.
like this :
Code:
if condition then
    if otherstuff=false then
        do stuff
    end if
else
    let's do something
end if

So right after your "Cancel = true" you need an End If
 
You will also find that if you indent your code especially if-endif blocks, it may improve readability.
Also, you should use code tags when posting any vba as Grumm has shown.
 

Users who are viewing this thread

Back
Top Bottom