记录集内随机取记录的代码
来源:
中文源码网 浏览:138 次 日期:2024-05-13 05:33:11
【下载文档: 记录集内随机取记录的代码.txt 】
记录集内随机取记录的代码
<% ' Moving to random record - Steven Jones' ExtensionIf Not(记录集名称.bof and 记录集名称.eof) Then' reset the cursor to the beginningIf (记录集名称.CursorType > 0) Then记录集名称.MoveFirstElse记录集名称.RequeryEnd If记录集名称_totalrn = -1记录集名称_totalrn = 记录集名称.RecordCount ' ony works on some recordsets, but much fasterIf (记录集名称_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记录集名称_totalrn=0While (Not 记录集名称.EOF)记录集名称_totalrn = 记录集名称_totalrn + 1记录集名称.MoveNextWend' reset the cursor to the beginningIf (记录集名称.CursorType > 0) Then记录集名称.MoveFirstElse记录集名称.RequeryEnd IfEnd If' now do final adjustments, and move to the random record 记录集名称_totalrn = 记录集名称_totalrn - 1If 记录集名称_totalrn > 0 ThenRandomize记录集名称.Move Int((记录集名称_totalrn + 1) * Rnd)End If End If' all done; you should always check for an empty recordset before displaying data%>