<%
' Moving to random record - Steven Jones' Extension
If Not(record set name.bof and record set name.eof) Then
' reset the cursor to the beginning
If (RecordSetName.CursorType > 0) Then
Recordset name.MoveFirst
Else
Recordset name.Requery
End If
Recordset name_totalrn = -1
RecordsetName_totalrn = RecordsetName.RecordCount ' ony works on some recordsets, but much faster
If (recordsetname_totalrn = -1) Then ' and if it didn't work, we still have to count the records.
' count the total records by iterating through the recordset
Recordset name_totalrn=0
While (Not record set name.EOF)
recordsetname_totalrn = recordsetname_totalrn + 1
Recordset name.MoveNext
Wend
' reset the cursor to the beginning
If (RecordSetName.CursorType > 0) Then
Recordset name.MoveFirst
Else
Recordset name.Requery
End If
End If
' now do final adjustments, and move to the random record
recordsetname_totalrn = recordsetname_totalrn - 1
If recordsetname_totalrn > 0 Then
Randomize
Recordset name.Move Int((recordset name_totalrn + 1) * Rnd)
End If
End If
' all done; you should always check for an empty recordset before displaying data
%>