D
Dale C Gray
So I've built this function and it works well enough?...but I want a date
range for the year between 1930 and 2003. I can't seem to get anything
greater than 1924. Part of the problem is I'm not clear on what I should be
using as my upper and lower date limits or I guess even how this formula
calculates! Any suggestions...comments....
Thanks all
Function GenDate() As Date
Dim db As DATABASE
Dim rst As Recordset
Dim lngcounter As Long
Dim dteRandom As Date
Dim yupper As Long, mupper As Long, dupper As Long
Dim ylower As Long, mlower As Long, dlower As Long
Dim yRandom As Long, mRandom As Long, dRandom As Long
Dim strCriteria As String
Set db = CurrentDb
Set rst = db.OpenRecordset("tblPatient", dbOpenDynaset)
Do Until rst.NoMatch
yupper = 2003
ylower = 1930
mupper = 12
mlower = 1
dupper = 30
dlower = 1
Restart:
Randomize
yRandom = ((Int((yupper - ylower)) * Rnd) + ylower)
Randomize
mRandom = Int(12 * Rnd)
Randomize
dRandom = Int(30 * Rnd)
lngRandom = CDate(yRandom + mRandom + dRandom)
rst.FindFirst "[DOB] = #" & lngRandom & "#"
If rst.NoMatch Then
GenDate = dteRandom
' Else: GoTo Restart:
End If
Loop
' Clean up.
rst.Close
Set db = Nothing
End Function
range for the year between 1930 and 2003. I can't seem to get anything
greater than 1924. Part of the problem is I'm not clear on what I should be
using as my upper and lower date limits or I guess even how this formula
calculates! Any suggestions...comments....
Thanks all
Function GenDate() As Date
Dim db As DATABASE
Dim rst As Recordset
Dim lngcounter As Long
Dim dteRandom As Date
Dim yupper As Long, mupper As Long, dupper As Long
Dim ylower As Long, mlower As Long, dlower As Long
Dim yRandom As Long, mRandom As Long, dRandom As Long
Dim strCriteria As String
Set db = CurrentDb
Set rst = db.OpenRecordset("tblPatient", dbOpenDynaset)
Do Until rst.NoMatch
yupper = 2003
ylower = 1930
mupper = 12
mlower = 1
dupper = 30
dlower = 1
Restart:
Randomize
yRandom = ((Int((yupper - ylower)) * Rnd) + ylower)
Randomize
mRandom = Int(12 * Rnd)
Randomize
dRandom = Int(30 * Rnd)
lngRandom = CDate(yRandom + mRandom + dRandom)
rst.FindFirst "[DOB] = #" & lngRandom & "#"
If rst.NoMatch Then
GenDate = dteRandom
' Else: GoTo Restart:
End If
Loop
' Clean up.
rst.Close
Set db = Nothing
End Function