Here's a routine that should help.
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.
'''''' from techonthenet
'---------------------------------------------------------------------------------------
' Last Modified:
'
' Inputs: N/A
' Dependency: N/A
'------------------------------------------------------------------------------
'
Function randomNumber(Lo As Integer, Hi As Integer) As Integer
10 On Error GoTo random_Error
20 Randomize
30 randomNumber = Int((Hi - Lo + 1) * Rnd + Lo)
40 On Error GoTo 0
50 Exit Function
random_Error:
60 MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure random of Module AccessMonster"
End Function
Test routine
Code:
'---------------------------------------------------------------------------------------
' Procedure : mytestOfRandomNumber
' Author : Jack
' Date : 11/18/2010
' Purpose : Create 10 random numbers between 3 and 300
'---------------------------------------------------------------------------------------
'
Sub mytestOfRandomNumber()
Dim a As Integer
Dim z As Integer
Dim i As Integer
10 a = 3
20 z = 300
30 For i = 1 To 10
40 Debug.Print i & " " & randomNumber(a, z)
50 Next i
End Sub
Sample run:
1 29
2 132
3 201
4 54
5 39
6 4
7 109
8 92
9 222
10 129