End If without block If

G

Guest

I CONTINUE TO GET COMPILE ERROR: END IF WITHOUT BLOCK IF!!!! CAN ANYONE TELL
ME WHAT IS WRONG?

Sorry so long I wanted to provide the detail --

In a query I have the following:
PPTE: ResultCalc([Episodes]![ACUT_ETG_IND],[Episodes]![Days_IND])

The following is performed when the ResultCalc function is called:

Function ResultCalc(EPTG_ACUT_ETG_IND As Double, Vec_rlpte_Dys_Qty As
Double) As Double

If (EPTG_ACUT_ETG_IND = 0) And (Vec_rlpte_Dys_Qty >= 0) And
(Vec_rlpte_Dys_Qty <= 30) Then ResultCalc = 0.5434 Else
If (EPTG_ACUT_ETG_IND = 0) And (Vec_rlpte_Dys_Qty >= 31) And
(Vec_rlpte_Dys_Qty <= 60) Then ResultCalc = 0.6769 Else
If (EPTG_ACUT_ETG_IND = 0) And (Vec_rlpte_Dys_Qty >= 61) And
(Vec_rlpte_Dys_Qty <= 90) Then ResultCalc = 0.7579 Else
If (EPTG_ACUT_ETG_IND = 0) And (Vec_rlpte_Dys_Qty >= 91) And
(Vec_rlpte_Dys_Qty <= 120) Then ResultCalc = 0.8168 Else
If (EPTG_ACUT_ETG_IND = 0) And (Vec_rlpte_Dys_Qty >= 121) And
(Vec_rlpte_Dys_Qty <= 150) Then ResultCalc = 0.8592 Else
If (EPTG_ACUT_ETG_IND = 0) And (Vec_rlpte_Dys_Qty >= 151) And
(Vec_rlpte_Dys_Qty <= 180) Then ResultCalc = 0.898 Else
If (EPTG_ACUT_ETG_IND = 0) And (Vec_rlpte_Dys_Qty >= 181) And
(Vec_rlpte_Dys_Qty <= 210) Then ResultCalc = 0.9257 Else
If (EPTG_ACUT_ETG_IND = 0) And (Vec_rlpte_Dys_Qty >= 211) And
(Vec_rlpte_Dys_Qty <= 240) Then ResultCalc = 0.9473 Else
If (EPTG_ACUT_ETG_IND = 0) And (Vec_rlpte_Dys_Qty >= 241) And
(Vec_rlpte_Dys_Qty <= 270) Then ResultCalc = 0.9646 Else
If (EPTG_ACUT_ETG_IND = 0) And (Vec_rlpte_Dys_Qty >= 271) And
(Vec_rlpte_Dys_Qty <= 300) Then ResultCalc = 0.9788 Else
If (EPTG_ACUT_ETG_IND = 0) And (Vec_rlpte_Dys_Qty >= 301) And
(Vec_rlpte_Dys_Qty <= 330) Then ResultCalc = 0.9908 Else
If (EPTG_ACUT_ETG_IND = 0) And (Vec_rlpte_Dys_Qty >= 331) And
(Vec_rlpte_Dys_Qty <= 365) Then ResultCalc = 1

End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If

End Function


Thank you,

JZ
 
J

Jeff Boyce

It is quite difficult to match up If and End If when the statements all run
together.

However, it looks to me like you have something like:

If <condition1> Then
<something1>
ElseIf <condition2> Then
<something2>
ElseIf ...
...
End If

If you are using "ElseIf", you only need a single End If.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
A

Albert D. Kallal

Sicne every single condtion has a test of 0, then we can stream line this:


try:


Function ResultCalc(EPTG_ACUT_ETG_IND As Double, _
Vec_rlpte_Dys_Qty As Double) As Double

If (EPTG_ACUT_ETG_IND = 0) Then

Select Case Vec_rlpte_Dys_Qty

Case 0 To 30
ResultCalc = 0.5434

Case 31 To 60
ResultCalc = 0.6769

Case 61 To 90
ResultCalc = 0.7579

Case 91 To 120
ResultCalc = 0.8168

Case 121 To 150
ResultCalc = 0.8592

Case 151 To 180
ResultCalc = 0.898

Case 181 To 210
ResultCalc = 0.9257

Case 211 To 240
ResultCalc = 0.9473

Case 241 To 270
ResultCalc = 0.9646

Case 271 To 300
ResultCalc = 0.9788

Case 301 To 330
ResultCalc = 0.9908

Case 331 To 365
ResultCalc = 1

End Select

End If

End Function

A bit easyer to read...
 
P

Per Larsen

In a case like this I would even consider putting the values (from the
Select part) into a table (see 'MyTable' below) and use the 'DLookup'
function:

Function ResultCalc(ByVal EPTG_ACUT_ETG_IND As Double, _
ByVal Vec_rlpte_Dys_Qty As Double) As Double

If ((EPTG_ACUT_ETG_IND = 0#) And _
((Vec_rlpte_Dys_Qty >= 0#) And _
(Vec_rlpte_Dys_Qty <= 365#))) Then

ResultCalc = DLookup("ResCalc", "MyTable", _
CStr(Vec_rlpte_Dys_Qty) & " Between VMin And VMax")

Else
ResultCalc = 0#
End If
End Function

Table 'MyTable':

VMin VMax ResCalc
0 30 0,5434
31 60 0,6769
61 90 0,7579
91 120 0,8168
121 150 0,8592
151 180 0,898
181 210 0,9257
211 240 0,9473
241 270 0,9646
271 300 0,9788
301 330 0,9908
331 365 1


Additional comments might be to consider using Integers (or Longs) for
the arguments when they are used in equality tests ('=', as opposed to
'<' and '>' or '<=' or '>='), and using 'ByVal' arguments when they are
not supposed to return values (i.e. possibly getting changed).
 
C

Carl Rapson

The other posters gave you some good redesign suggestions, but just to
answer your question, you have one too many End Ifs. The final If statement
doesn't require and End If, because it's of the form:

If <condition> Then <do something>

You only need the End If if your <do something> is on a separate line:

If <condition> Then
<do something>
End If

HTH,

Carl Rapson
 
R

raskew via AccessMonster.com

Hi -

This is kind of 'air code' since I don't have actual data to test it on.
Nonetheless, think you can probably use the Choose() function to simplify all
of those nested Iif() statements. Example:

Public Function ResultCalc(EPTG_ACUT_ETG_IND As Double, Vec_rlpte_Dys_Qty As
Double) As Double

If EPTG_ACUT_ETG_IND = 0 And Vec_rlpte_Dys_Qty <= 0 Then
ResultCalc = 0.5434
Else
ResultCalc = Choose((Vec_rlpte_Dys_Qty \ 30) + 1, 0.5434, 0.6769, 0.
7579, 0.8168, 0.8592, 0.898, 0.9257, 0.9473, 0.9646, 0.9788, 1)
End If

End Function


Carl said:
The other posters gave you some good redesign suggestions, but just to
answer your question, you have one too many End Ifs. The final If statement
doesn't require and End If, because it's of the form:

If <condition> Then <do something>

You only need the End If if your <do something> is on a separate line:

If <condition> Then
<do something>
End If

HTH,

Carl Rapson
I CONTINUE TO GET COMPILE ERROR: END IF WITHOUT BLOCK IF!!!! CAN ANYONE
TELL
[quoted text clipped - 53 lines]
 

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