Hi,
The following code should select the specified number of records randomly
from the database
<%
....
query = "SELECT [Titles.Index] FROM [Titles]"
Set RS = Server.CreateObject("ADODB.Recordset")
' Response.Write query
RS.Open query, objConn, 1, 2, 1
Randomize Timer ' Seed the rnd function
Response.Write RS.RecordCount & "<br>"
For c = 1 To numVals
intRnd = 0 ' Set to default value to allow the Do Until to check against
a value
Do
intRnd = (Int(Rnd * RS.RecordCount)) ' Pick a number between 0 and
Number of records - 1
Response.Write c & " " & intRnd & " " & retString & " " &
DontMatchWith & "<br>"
RS.Move intRnd ' Goto that record
Loop While InStr(DontMatchWith, Right("000000" & intRnd, 6))
retString = retString & Right("000000" & intRnd, 6)
DontMatchWith = DontMatchWith & Right("000000" & intRnd, 6)
Next
....
%>
The loop works a random number of times (somewhat appropriately :-)) before
crashing with the following error:
ADODB.Recordset error '800a0bcd'
Either BOF or EOF is True, or the current record has been deleted. Requested
operation requires a current record.
/Includes/QuizFunx.asp, line 31
where line 31 is RS.Move intRnd ' Goto that record
I've compacted the database and it does seem to be working as I wish right
to the point where it crashes.
The output of this function is a string that will be used to pull out random
titles from the table.
Can you suggest a solution to the problem, or another way of generating the
random numbers
TiA
--
John Fairhurst
http://www.johnsbooks.co.uk
jo**@johnsbooks.co.uk