Assume that the datasheet has a unique ID field and at least one record. The method of randomly accessing one of the records is very simple and can be divided into four steps:
1. Get the total number of records N.
2. Store all ID numbers in an array
3, to produce a random number of not greater than N m
4, take out the first m ID number from the array, query the data table, get the record data.
Here's a partial code:
$#@60;%
set conn = Server.CreateObject(‘ADODB.Connection‘)
conn.open ‘$#@60;conn string$#@62;‘
‘ ***** (step 1) *****
set rs = conn.execute(‘Select count(id) from someTable‘)
rCount = rs(0)
‘ ***** (step 2) *****
set rs = conn.execute(“select id from someTable”)
cnt = 1
dim RRs
redim RRs(rCount)
do while not rs.eof
RRs(cnt) = rs(0)
cnt = cnt + 1
rs.movenext
loop
‘ ***** (step 3) *****
randomize
currentRR = cLng(rnd*rCount+0.5)
ID = RRs(currentRR)
‘ ***** (step 4) *****
sql = “select otherfield from someTable where id=” & ID
set rs = conn.execute(sql)
response.write “ID # ” & ID & “ = ” & rs(0)
rs.close: set rs = nothing
conn.close: set conn = nothing
%$#@62;
For SQL Server, there are more efficient methods. For example, design two stored procedures. I'm just clarifying some ideas here, and I hope this idea can be used in both access and SQL Server.