One simple solution's to use the SQL COUNT method. This assumes you want the number of rows and not the data itself.
<%
Set rsscroll = Server.CreateObject("ADODB.Recordset")
Dim strSQLscroll, rsscroll, intRow
strSQLscroll = "SELECT COUNT(*) AS Total FROM tblItems WHERE expiration_date > getdate();"
rsscroll.open strSQLscroll, oConn
response.write rsscroll("Total")
rsscroll.close: set rsscroll = nothing
oConn.close: set oConn = nothing
%>
This returns one row with a single value called "Total." (Read on if you need both the row count and data.)
Your query code uses a default RecordSet, which returns data in "forward-only" mode for efficiency. It'll step through row-by-row, but doesn't know the actual count. (This mode also sets the RecordSet.RecordCount to -1, so the field isn't useful for you.)
RecordSet.Open's "Cursor Type" parameter lets you change to "Keyset" mode (parameter value 1), which does set the RecordCount field to the number of data rows. ("Lock Type" and "Command Type" parameters included for completeness, but they don't figure into this answer.)
RecordsetObject.Open "TableName|SQLStatement", ConnectionObject [,Cursor Type] [,Lock Type] [,Command Type]
Add this parameter to your code's RecordSet.Open call and then check RecordCount.
<%
Set rsscroll = Server.CreateObject("ADODB.Recordset")
Dim strSQLscroll, rsscroll, intRow
strSQLscroll = "SELECT * FROM tblItems where expiration_date > getdate() order by expiration_date desc;"
rsscroll.open strSQLscroll, oConn, 1
intRow = rsscroll.RecordCount
' ... do something with intRow
rsscroll.close: set rsscroll = nothing
oConn.close: set oConn = nothing
%>
If database performance means anything to your situation, the RecordSet.GetRows() method's much more efficient.
<%
Dim rsscroll, intRow, rsArray
Set oConn = CreateObject("ADODB.Connection")
oConn.open "<connection string>"
strSQLscroll = "SELECT * FROM tblItems where expiration_date > getdate() order by expiration_date desc"
Set rsscroll = conn.execute(strSQLscroll)
if not rsscroll.eof then
rsArray = rsscroll.GetRows()
intRow = UBound(rsArray, 2) + 1
response.write "rows returned: " & intRow
' ... do any other operations here ...
end if
rsscroll.close: set rsscroll = nothing
oConn.close: set oConn = nothing
%>