I'm trying to adjust this coding to select only userID's from table Attendance where [Programs] and [Language] match those form table CFRRR but I'm getting an error saying that I have too few parameters. I'm sure but it may be because I'm not referring to the other table here: Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
Here's the full code:
Public Function GetNextAssignee(program As String, language As String, username As String) As Long
' Returns UserID as a Long Integer with the lowest [TS] value,
' and updates same [TS] by incremented with 1.
Dim db As dao.Database
Dim rs As dao.Recordset
Dim strSQL As String
Set db = CurrentDb
strSQL = "SELECT TOP 1 userID FROM attendance WHERE [Programs] LIKE CFRRR.program AND [Language] LIKE CFRRR.language AND [Status] = 'Available' ORDER BY TS ASC"
Debug.Print strSQL
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
If Not rs.BOF And Not rs.EOF Then
strSQL = "UPDATE attendance SET TS = " & DMax("[TS]", "attendance") + 1 & " WHERE [userID]= " & rs!userID
db.Execute strSQL, dbFailOnError
GetNextAssignee = rs!userID
GetNextWorker = rs!username
Else
'Field TS has NO VALUE FOR ALL RECORDS!
'Code calling this function should check for a return of 0 indicating an error.
GetNextAssignee = 0
End If
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
End Function