Hi,
Thanks for the advice. But I found out where the problem was coming from.
The error "Error Type (0x80020009) Exception occurred" came from having the
"If..Then" statement come after the Rs.Movenext. When the object
Rs.Movenext went past the last record , Rs("StyleNo") did not contain
anything in it any more. So it came up with an error. Here is more of the
code that I was working on.
SQLstmt = "SELECT * FROM tblQuotation WHERE UserName='" &
Session("username") & "' ORDER BY StyleNo, Color"
Set Rs = conn.execute(SQLstmt)
Do While Not Rs.EOF
Response.Write "Your Contract No is " & Rs("ContractNo") & "<br>"
Response.Write "<table border='1' width='200'>"
aCount = aCount + 1
arrStyleNo(aCount) = Rs("StyleNo")
arrPic(aCount) = Rs("Pic")
Response.Write "<tr><td><B>Style No</B></td><td>" & (arrStyleNo(aCount)) &
" " & Rs("Color") & "</td></tr>"
Response.Write "<tr><td colspan='2' align='right'><A HREF='" &
(arrPic(aCount)) & "'><IMG SRC='" & (arrPic(aCount)) & "' width='153'
height='230'></A></td></tr>"
Response.Write "<tr><td><B>Price</B></td><td> $" & Rs("UnitPrice") &
"</td></tr>"
Response.Write "<tr><td><B>Fabrication</B></td><td>" &Rs("Desc") &
"</td></tr>"
Response.Write "</table>"
Response.Write "<BR><BR>"
Rs.Movenext
If Rs("StyleNo") <> arrStyleNo(aCount) Then
bCount = aCount
aCount = 0
For iCounter = 1 to bCount
Response.Write "Hello"
Next
Else
End If
Loop
Rs.Close
Set Rs = Nothing
In order to solve the problem , I took the If..Then statement an put it
before the Rs.Movenext and I also added more arrays to store the records.
The records of the database would be compared by using the arrays rather
than comparing with Rs object directly. The code that works is as follows:
SQLstmt = "SELECT * FROM tblQuotation WHERE UserName='" &
Session("username") & "' ORDER BY StyleNo, Color"
Set Rs = conn.execute(SQLstmt)
Do While Not Rs.EOF
aCount = aCount + 1
arrStyleNo(aCount) = Rs("StyleNo")
arrColor(aCount) = Rs("Color")
arrDesc(aCount) = Rs("Desc")
arrPic(aCount) = Rs("Pic")
arrT1(aCount) = Rs("T1")
arrT2(aCount) = Rs("T2")
arrT3(aCount) = Rs("T3")
arrUnitPrice(aCount) = Rs("UnitPrice")
arrQty(aCount) = arrT1(aCount) + arrT2(aCount) + arrT3(aCount)
arrAmt(aCount) = arrQty(aCount) * arrUnitPrice(aCount)
Rs.MoveNext
Loop
Rs.Close
Set Rs = Nothing
Response.Write "<table border='0' width='800'>"
For iCounter = 1 to aCount
If NOT arrStyleNo(iCounter -1) = arrStyleNo(iCounter) Then
Response.Write said:
<td><B>T2</B></td><td><B>T3</B></td><td><b>Qty</b></td><td><B>Unit
Price</B></td><td><B>Amount</B></td></tr>"
End If
Response.Write "<tr><td>" & arrStyleNo(iCounter) & "</td><td>" &
arrColor(iCounter) & "</td><td>" & arrDesc(iCounter) & "</td><td>" &
arrT1(iCounter) & "</td><td>" & arrT2(iCounter) & "</td><td>" &
arrT3(iCounter) & "</td><td>" & arrQty(iCounter) & "</td><td> $" &
arrUnitPrice(iCounter) & "</td><td> $" & arrAmt(iCounter) & "</td></tr>"
If arrStyleNo(iCounter) <> arrStyleNo(iCounter + 1) Then
Response.Write "<tr><td colspan='9'><table><tr>"
For jCounter = cCount to iCounter
Response.Write "<td><a href='" & arrPic(jCounter) & "'><img src='" &
arrPic(jCounter) & "' width='153' height='230'></a></td>"
Next
cCount = jCounter
Response.Write "</tr></table></td></tr></td></tr></table><tr><td
colspan='9'> </td></tr><tr><td colspan='9'> </td></tr>"
End If
Next
Response.Write "</table><BR><BR>"
End If
I basically placed all of the records into arrays first and then I retrieved
and compared the contents of the arrays using the "For..Next" loops.
Thanks for all the advice.