Update not working

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top