If, ElseIf, Else, End If

  • Thread starter Thread starter Christina
  • Start date Start date
C

Christina

I have got a form that uses many If statements. The form
use to work, but I recently had to change it to accomodate
new post type, and it almost seems to have gone a little
crazy. It keeps giving me an error "Else without If
block" or "End If without If block". I've gone through
the entire code several times and have not found anything
that is mismatched. I've also used the immediate box to
try to isolate a statment that may be written incorrectly,
and havn't found any. The other thing that seems wierd is
that if I change the Elseif statements to If statements,
so there are a series of If statements with no Else's or
End if's, the code just about works. I know that this
isn't correct, but I am at a loss as to what may be
happening. The code is too long to include here, but does
anyone have any suggestions about what to look for while
I'm trying to pinpoint the problem?
 
Hi Christina,
It is easier to spot missing ends if you indent code. for
example...

If SysCmd(acSysCmdGetObjectState, acForm, strFormName)
<> conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView
Then
IsLoaded = True
End If
End If

.... hopefully the post shows the if/end if statements with
the same indent level. any line between the if/end if are
indented again.

Something to consider is using Select Case statements to
simplify comparitive tests.

Another thing to consider is that an error message is a
best guess. That is the compiler has found an error at OR
BEFORE the indicated line. Thus if you find that you have
correctly paired if with end if, you then must examine
each line above the line highlighted.

Luck
Jonathan
 
Back
Top