Hi,
I have a random number generated based on a query's record count. I would then like to retrieve a field value from that query based on the index that is generated.
The code below works and generates a random number based on the query's record count. But I do not know how to retrieve the EmployeeID field with the random index generated. I'm not sure if I need to open a recordset. I basically just want to go right to the record index that is generated and retrieve the EmployeeID, without having to loop through the records. Is this possible?
Code:
Private Sub btnRandomEmployeeName_Click()
Dim randomEmployeeNum As Integer
randomEmployeeNum = Int((EmployeeCount - 1 + 1) * Rnd + 1)
MsgBox randomEmployeeNum
End Sub
Private Function EmployeeCount() As Integer
EmployeeCount = DCount("[EmpID]", "qryActiveEmployees")
End Function