Select random record button in form (not working how I'd like)

dcfi6052

Registered User.
Local time
Yesterday, 16:41
Joined
Jan 25, 2012
Messages
34
Hello everyone,

I want to make a button that selects a random record in a form. I used code from a previous thread:
http://www.access-programmers.co.uk/forums/showthread.php?t=248325

Code:
Dim RecordNumber As Integer Dim RecSor As String RecSor = Me.RecordSource RecordNumber = CInt(Rnd() * DCount("*", RecSor)) DoCmd.GoToRecord , , acFirst Me.Recordset.Move RecordNumber

It seems to work exactly how I want it to except that it selects the first record every time before selecting a new random record. I thought this could be hidden by using the
Code:
application.echo false
function, but that doesn't seem to hide it from selecting the first record.

Does anyone know how to work around this or re-write this code to not select the first record while still keeping it random?
 

Users who are viewing this thread

Back
Top Bottom