Link to home
Start Free TrialLog in
Avatar of Bob Schneider
Bob SchneiderFlag for United States of America

asked on

Error When Recordset Returns No Data

I got a type mismatch error on the Finishers = rs.GetRows(sql) in the following code when the query returned no data.  I thought the if statement there would prevent that.  any thoughts?

    sql = "SELECT RosterSrvrID, Bib, RaceTime, RaceSrvrID FROM IndRslts WHERE IndRsltsID > " & lLastRcd & " AND MeetsID = "
    sql = sql & lMeetID & " AND Place > 0 AND FnlScnds > 0 AND Excludes = 'n' ORDER BY RaceSrvrID, FnlScnds, Place"
    Set rs = conn.Execute(sql)
    If Not rs.BOF And Not rs.EOF Then
        Finishers = rs.GetRows(sql)
    End If
    Set rs = Nothing


Open in new window

Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Try

 If rs.RecordCount >0 Then
what if trying this instead?

Finishers = rs.GetRows

Open in new window


Try to count the records:

Dim sql         As String
Dim RecordCount As Long

sql = "SELECT RosterSrvrID, Bib, RaceTime, RaceSrvrID FROM IndRslts WHERE IndRsltsID > " & lLastRcd & " AND MeetsID = "
sql = sql & lMeetID & " AND Place > 0 AND FnlScnds > 0 AND Excludes = 'n' ORDER BY RaceSrvrID, FnlScnds, Place"
Set rs = conn.Execute(sql)
If Not rs.BOF And Not rs.EOF Then
    ' Count records.
    rs.MoveLast
    RecordCount = rs.RecordCount
    rs.MoveFirst
    Finishers = rs.GetRows(RecordCount)
End If
rs.Close

Set rs = Nothing

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of DBAduck - Ben Miller
DBAduck - Ben Miller
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bob Schneider

ASKER

Thank you all.  The sql parameter was the problem...