L
Leslie
I am calling a function to pull a random employee, which works but I would
like to also set the field "RandomSelected" to true, this is the part that I
am having problems with. My code is:
Function FindRandom(wrkName As String)
Dim MyDB As Database
Dim MyRS As Recordset
Dim strSQL As String
Dim SpecificRecord As Long, i As Long, NumOfRecords As Long
Set MyDB = CurrentDb()
Set MyRS = MyDB.OpenRecordset("SELECT tblEmployees.ID,
tblEmployees.FullName, tblEmployees.RandomSelected " & _
"FROM tblEmployees WHERE (((tblEmployees.RandomSelected)=False));")
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
wrkName = MyRS!FullName
strSQL = ("UPDATE tblEmployees.ID SET tblEmployees.RandomSelected = True
(((WHERE tblEmployees.ID) = MyRS!ID));")
DoCmd.RunSQL strSQL
FindRandom = MyRS(wrkName)
like to also set the field "RandomSelected" to true, this is the part that I
am having problems with. My code is:
Function FindRandom(wrkName As String)
Dim MyDB As Database
Dim MyRS As Recordset
Dim strSQL As String
Dim SpecificRecord As Long, i As Long, NumOfRecords As Long
Set MyDB = CurrentDb()
Set MyRS = MyDB.OpenRecordset("SELECT tblEmployees.ID,
tblEmployees.FullName, tblEmployees.RandomSelected " & _
"FROM tblEmployees WHERE (((tblEmployees.RandomSelected)=False));")
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
wrkName = MyRS!FullName
strSQL = ("UPDATE tblEmployees.ID SET tblEmployees.RandomSelected = True
(((WHERE tblEmployees.ID) = MyRS!ID));")
DoCmd.RunSQL strSQL
FindRandom = MyRS(wrkName)