D
Dale C Gray
This function is supposed to randomly generate a number, look to see if it
exits in the recordset, if not, udate the record....if it does find an
existing number, the intention was the loop would start the process over
again until the random number was updated with one that does not previously
exist. I occassionally get duplicates? Have I missed something?
Thanks in advance
Function RandomNum()
Dim db As DATABASE
Dim rst As Recordset
Dim lngcounter As Long
Dim lngRandom As String
Dim upperlimit As Long
Dim lowerlimit As Long
Dim strCriteria As String
Dim mynum as Integer
Set db = CurrentDb
Set rst = db.OpenRecordset("tblPatient", dbOpenDynaset)
Do Until rst.NoMatch
upperlimit = 999999999
lowerlimit = 100000000
Randomize
lngRandom = Int((upperlimit - lowerlimit + 1) * Rnd + lowerlimit)
rst.FindFirst "[mynum] = 'lngRandom'"
If rst.NoMatch Then
mynum = lngRandom
End If
Loop
' Clean up.
rst.Close
Set db = Nothing
End Function
exits in the recordset, if not, udate the record....if it does find an
existing number, the intention was the loop would start the process over
again until the random number was updated with one that does not previously
exist. I occassionally get duplicates? Have I missed something?
Thanks in advance
Function RandomNum()
Dim db As DATABASE
Dim rst As Recordset
Dim lngcounter As Long
Dim lngRandom As String
Dim upperlimit As Long
Dim lowerlimit As Long
Dim strCriteria As String
Dim mynum as Integer
Set db = CurrentDb
Set rst = db.OpenRecordset("tblPatient", dbOpenDynaset)
Do Until rst.NoMatch
upperlimit = 999999999
lowerlimit = 100000000
Randomize
lngRandom = Int((upperlimit - lowerlimit + 1) * Rnd + lowerlimit)
rst.FindFirst "[mynum] = 'lngRandom'"
If rst.NoMatch Then
mynum = lngRandom
End If
Loop
' Clean up.
rst.Close
Set db = Nothing
End Function