heres the page im testing with:
Dim oConn, oRS, randNum, strSQL, strDate, strComments, intCount
Set oConn=Server.CreateObject("ADODB.Connection")
Set oRS=Server.CreateObject("ADODB.recordset")
oConn.Provider="Microsoft.Jet.OLEDB.4.0"
oConn.Open Server.MapPath("comments.mdb")
strSQL = "SELECT DATE_TEXT, COMMENTS_TEXT FROM TBL_COMMENTS"
oRS.Open strSQL, oConn, adOpenStatic, adLockReadOnly
For intCount = 1 To 2
Randomize()
randNum = CInt((oRS.RecordCount - 1) * Rnd)
oRS.Move randNum
Response.Write("recordcount: " & oRS.RecordCount & "<br>")
Response.Write("random number: " & randNum & "<br>")
Response.Write(oRS("DATE_TEXT") & "<br>")
Response.Write(oRS("COMMENTS_TEXT") & "<br>")
Response.Write("<br>")
Next
oRS.close
oConn.close
Set oConn = nothing
Set oRS = nothing
[quoted text, click to view] "Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message
news:ezNZFJX4GHA.3452@TK2MSFTNGP05.phx.gbl...
> Joe Reynolds wrote:
>> hi everyone. i have the following code that pulls a random record
>> from an access database:
>>
>> Randomize()
>> randNum = CInt((oRS.RecordCount - 1) * Rnd)
>> oRS.Move randNum
>> Response.Write(oRS("FIELD1") )
>>
>> this works fine. it opens a recordset, gets a count of numrecords,
>> then moves to a random record within that count.
>> if i put this in a loop it fails
>>
>> For i = 1 To 3
>> Randomize()
>> randNum = CInt((oRS.RecordCount - 1) * Rnd)
>> oRS.Move randNum
>> Response.Write(oRS("FIELD1"))
>> Next
>>
>> this might load on the first try, but a refresh usually produces the
>> error "either eof or bof is true etc..."
>> how is this possibly happening?
>
> I can't say without seeing more of the code (what cursor type are you
> using?).
>
> Here is a better way to get a random record. It requires the existence
> of an autonumber field in your table:
>
>
http://www.adopenstatic.com/faq/randomrecord.asp >
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.
>
>