Random Number Generator

Status
Not open for further replies.

velcrowe

Registered User.
Local time
Today, 15:39
Joined
Apr 26, 2006
Messages
86
I would like to create a simple access program to assign locker numbers between 1 and 750 to employees. Whenever I want to give an employee a new locker number, I would like to click a button to assign them a new number and then enter the date of the assignment. Is this possible and simple?:rolleyes:
 
Thanks. To edit my last question. I have 100 persons who have lockers. I want to randomly pick five men and five women for locker inspections. Would the Rnd() function apply these sets of data? Can I randomly select five non-repeating men or women?
 
Last edited:
The following function will do that for you..


Function FindRandom (RecordSetName As String, Fieldname As String)
Dim MyDB As Database
Dim MyRS As Recordset
Dim SpecificRecord As Long, i As Long, NumOfRecords As Long

Set MyDB = CurrentDB()
Set MyRS = MyDB.OpenRecordset(RecordSetName, DB_Open_Dynaset)
On Error GoTo NoRecords
MyRS.MoveLast
NumOfRecords = MyRS.RecordCount
SpecificRecord = Int(NumOfRecords * Rnd)
If SpecificRecord = NumOfRecords Then
SpecificRecord = SpecificRecord - 1
End If
MyRS.MoveFirst
For i = 1 To SpecificRecord
MyRS.MoveNext
Next i
FindRandom = MyRS(Fieldname)

Exit Function
NoRecords:
If Err = 3021 Then
MsgBox "There Are No Records In The Dynaset", 16, "Error"
Else
MsgBox "Error - " & Err & Chr$(13) & Chr$(10) & Error, _
16, "Error"
End If
FindRandom = "No Records"
Exit Function
End Function
 
Random Generator

I am using only three fields...locker number, name, and date(to keep track of query run date) on my table, query, and form.

Should I place this code in the General Declaration of the form and do I need a requer command button to run on instance from the form?
 
yes, this code definitely goes into a module
 
Status
Not open for further replies.

Users who are viewing this thread

Back
Top Bottom