View Single Post ยป More
Old 06-24-2014, 10:06 PM   #1 (permalink)
Status: Junior Member
Posts: 3

Default find a random record

I am trying to find a random record in an access table using VBA and the click of a button called "RandomWOD".

Currently, this is my code:

Option Compare Database

Private Sub RandomWOD_Click()
Dim RecordNumber As Integer
Dim RecSor As String
RecSor = Me.RecordSource
RecordNumber = CInt(Rnd() * DCount("*", RecSor))
DoCmd.GoToRecord , , acFirst
Me.Recordset.Move RecordNumber
End Sub

It appears to return random records for a while, but at some point I get the error:

Run-time error '3021':

No current record.

I am not sure how to solve this problem.

I also am not sure it is returning a truly random number. It may be giving me pseudo-random answers in the same order each time I open the database up and push the button....

Any help would be greatly appreciated.
Voluntaryist is offline   Reply With Quote