PDA

View Full Version : CASE SELECT Statement


oracle
12-10-2005, 05:30 AM
I'm getting the following error:
Error Type:
ADODB.Recordset (0x800A0CC1)
Item cannot be found in the collection corresponding to the requested name or ordinal.

for the below code: [error points to the bold line]

Rs.Open strSQL,Conn, 1,3

Dim a
Dim Check, CurInsured, PrevInsured, Insured(100)
Dim Fire(100), Engr(100), Motor(100), MISC(100), Bond(100)
Dim PAI(100), LIB(100), OIL(100), Aviation(100), Hull(100), Cargo(100), Med(100)
' Move to the first record
rs.movefirst

a=1

do while not rs.EOF

CurInsured = rs("Insured")

For i=1 to a

If CurInsured = Insured(a) then
Check =1

SELECT CASE rs("Major_Class")

CASE "FIR"
Fire(a)=Fire(a) + rs("sum_insured")

CASE "Engr"
Engr(a)=Engr(a) + rs("sum_insured")

CASE "Mot"
Motor(a)=Motor(a) + rs("sum_insured")

CASE "MISC"
MISC(a)=MISC(a) + rs("sum_insured")

CASE "BON"
Bond(a)=Bond(a) + rs("sum_insured")

CASE "PAI"
PAI(a)=PAI(a) + rs("sum_insured")

CASE "LIB"
LIB(a)=LIB(a)+ rs("sum_insured")

CASE "OIL"
OIL(a)=OIL(a)+ rs("sum_insured")

CASE "AVI"
AVI(a)=AVI(a) + rs("sum_insured")

CASE "HUL"
HULL(a)=HULL(a) + rs("sum_insured")

CASE "CGO"
CARGO(a)=CARGO(a)+ rs("sum_insured")

CASE "MED"
MED(a)=MED(a)+ rs("sum_insured")

End SELECT

End if

If check =0 then
Insured(a)= rs("Insured")


SELECT CASE rs("Major_Class")
CASE "FIR"
Fire(a)=rs("sum_insured")

CASE "Engr"
Engr(a)=rs("sum_insured")

CASE "Mot"
Motor(a)=rs("sum_insured")

CASE "MISC"
MISC(a)=rs("sum_insured")

CASE "BON"
Bond(a)=rs("sum_insured")

CASE "PAI"
PAI(a)=rs("sum_insured")

CASE "LIB"
LIB(a)=rs("sum_insured")

CASE "OIL"
OIL(a)=rs("sum_insured")

CASE "AVI"
AVI(a)=rs("sum_insured")

CASE "HUL"
HULL(a)=rs("sum_insured")

CASE "CGO"
CARGO(a)=rs("sum_insured")

CASE "MED"
MED(a)=rs("sum_insured")

End SELECT

End If



a = a + 1
rs.MoveNext ' Movenext

Next
loop


rs.movefirst

do while not rs.EOF
%>

<tr>
<td><%= rs("acceptance_no") %></td>
<td><%= rs("date_of_offer") %></td>
<td><%= rs("buss_type") %></td>
<td><%= rs("ceding_co") %></td>
<td><%= rs("insured") %></td>
<td><%= rs("inception_date") %></td>
<td><%= rs("expiry_date") %></td>
<td><%= rs("mpib_share") %></td>
<td><%= rs("Fire") %></td>
<td><%= rs("Engr") %></td>
<td><%= rs("Motor") %></td>
<td><%= rs("MISC") %></td>
<td><%= rs("Bond") %></td>
<td><%= rs("PAI") %></td>
<td><%= rs("LIB") %></td>
<td><%= rs("OIL") %></td>
<td><%= rs("AVI") %></td>
<td><%= rs("HULL") %></td>
<td><%= rs("CARGO") %></td>
<td><%= rs("Medical") %></td>
<td><%= rs("TotalGrossPremium") %></td>
</tr>
<%
rs.MoveNext ' Movenext
loop

%>

Please someone help me!!TQ.

Brandoe85
12-10-2005, 05:36 AM
Usually means you're trying to access a field from your recordset that doesn't exist. Check your table and make sure "Major_Class" is indeed a column in your table.

Good luck;

oracle
12-12-2005, 08:00 AM
Yes..I'm using the right field name.

Is there any other possibilities? Am I writing the SELECT CASE sequence in the correct manner.

The pupose of the SELECT case statement is to check whether the insured name is repeating...if it does repeat...then it should add up the second record total premium to the insured's class.

Please help me out.TQ.

hinch
12-12-2005, 11:41 AM
your select case's look fine

turn off friendly http error messages then you may get more helpful debug messages

BaldEagle
12-14-2005, 12:48 AM
a = a + 1
rs.MoveNext ' Movenext

Next
loop

I'd say your problem may be here. You are moving your recordset forward such that the do while...loop structure has no knowledge of it and therefore can't terminate when you hit EOF. Hence, you eventually are getting no record to act on.

BaldEagle