Here's a sample function to produce random numbers.
Code:
'---------------------------------------------------------------------------------------
' Procedure : randomNumber
' Author : Jack
' Created : 11/18/2010
' Purpose : To Generate Random numbers between and including a range of numbers.
'Lo and Hi are the lowest and highest random numbers you wish to generate.
'
'The Randomize keyword is critical to getting different results for each Access session.
'=======================================================================================
'---------------------------------------------------------------------------------------
' Last Modified:
'
' Inputs: N/A
' Dependency: N/A
'------------------------------------------------------------------------------
'
Function randomNumber(Lo As Long, Hi As Long) As Long
10 On Error GoTo randomNumber_Error
20 Randomize
30 randomNumber = Int((Hi - Lo + 1) * Rnd + Lo)
40 On Error GoTo 0
randomNumber_Exit:
50 Exit Function
randomNumber_Error:
60 MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure randomNumber of Module AccessMonster"
70 GoTo randomNumber_Exit
End Function
And here is a test routine to call the function.
Code:
' Procedure : mytestOfRandomNumber
' Author : Jack
' Date : 11/18/2010
' Purpose : Create 10 random numbers between a and z
'---------------------------------------------------------------------------------------
'
Sub mytestOfRandomNumber()
Dim A As Long
Dim Z As Long
Dim i As Integer
10 A = 1
20 Z = 26
30 For i = 1 To 15
40 Debug.Print i & " " & randomNumber(A, Z)
50 Next i
60 On Error GoTo 0
70 Exit Sub
mytestOfRandomNumber_Error:
80 MsgBox "Error " & Err.Number & " in line " & Erl & " (" & Err.Description & ") in procedure mytestOfRandomNumber of Module AccessMonster"
End Sub
Results of 3 sample runs:
1 4
2 22
3 2
4 15
5 15
6 3
7 7
8 13
9 1
10 11
11 1
12 13
13 22
14 9
15 22
1 22
2 19
3 2
4 20
5 5
6 23
7 1
8 4
9 2
10 8
11 16
12 24
13 2
14 2
15 7
1 5
2 2
3 17
4 18
5 8
6 11
7 21
8 25
9 19
10 9
11 7
12 7
13 6
14 7
15 26
Hope it's helpful.