Can't get code to work

Shredsec.com

New member
Local time
Today, 03:05
Joined
Jan 21, 2013
Messages
6
I'm using this code on a button to find random records in my database but it doesn't find random records - it goes through the same sequence of records.

Private Sub Random_record_Click()
DoCmd.GoToRecord , , acGoTo, Int(Rnd() * Me.RecordsetClone.RecordCount) + 1
End Sub
 
From my old vb days , i remember that Int((6)*Rnd()+1) would produce a random number from 1 to 6 . where as Rnd() produces fractional numbers zero to One. Hope this is of some help
 
Try reversing the order like this
DoCmd.GoToRecord , , acGoTo, Int(Me.RecordsetClone.RecordCount * Rnd() + 1)
David
 
Assuming the rest of your code is accurate, try this:

Code:
Private Sub Random_record_Click()
[B]Randomize[/B]
DoCmd.GoToRecord , , acGoTo, Int(Rnd() * Me.RecordsetClone.RecordCount) + 1
End Sub
 

Users who are viewing this thread

Back
Top Bottom