Search code examples
stringtextasp-classicrecordset

Error when trying to do record set with string field, works with numbers


I'm trying to display a distinct set of values in a form. When I use a number field all works fine. When trying to use a string field, I get this error.

Microsoft VBScript runtime error '800a000d'
Type mismatch: 'QRs(...)'
/RAY-QUICK.asp, line 92


<option selected value="0"> - Ft_ProdCode - SQL tekst  </option>
<% ' -----------------------------------------------   START SQL QUERY
Set MyConn = Server.CreateObject("ADODB.Connection") 
MdbFilePath = Server.MapPath("/db/quickd.mdb") 
MyConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"

SQL_Query = "SELECT DISTINCT Quick.[Ft_ProdCode] FROM Quick;"

Set RS = MyConn.Execute(SQL_query) 
If Not Rs.EOF Then
    QRs = Rs.GetRows()
        QaantVelden = UBound(QRs):QaantRecords = UBound(QRs, 2)
Else
    AnaantRecords = -1
End If

Rs.Close
Set Rs = Nothing
myConn.Close
Set myConn = Nothing

DeCEL=0 : do while DeCEL<>Qaantrecords+1
    if QRS(0,deCEL )>0 then
        %>
        <option value="<%=QRS(0,deCEL )%>"><%=QRS(0,deCEL )%></option>
        <%  end if
    DeCEL=DeCEL+1 : loop : DeCEL=0

%>
</select>

Solution

  • Try doing away with the array logic and just loop the rs instead:

    Set MyConn = Server.CreateObject("ADODB.Connection") 
    MdbFilePath = Server.MapPath("/db/quickd.mdb") 
    MyConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"
    
    Set RS = MyConn.Execute("SELECT DISTINCT Quick.[Ft_ProdCode] FROM Quick;") 
    
    do while not RS.eof
        response.write("<option value=""" & RS("Ft_ProdCode") & """>" & RS("Ft_ProdCode") & "</option>")
        RS.movenext
    loop
    
    Rs.Close
    Set Rs = Nothing
    myConn.Close
    Set myConn = Nothing