Hi,
I use the following code to assign records by round robin in a few of my databases.
Code:
Option Compare Database
Option Explicit
Function RR_assignAL3_unsuccessful() As Boolean
'On Error GoTo Err_RR_assignAL3_unsuccessful
Dim db As DAO.Database
Dim rsSpecialists As DAO.Recordset
Dim rsProcessing As DAO.Recordset
Dim strSQL As String
'Specialist assignments table
strSQL = "Select Specialist, ID " & _
"FROM ztblSpecialist " & _
"WHERE Inactive = 0"
Set db = CurrentDb()
Set rsSpecialists = db.OpenRecordset(strSQL)
'Select records
strSQL = "Select * from tbl_AL3_unsuccessful " & _
" WHERE Specialist IS NULL "
Set rsProcessing = db.OpenRecordset(strSQL)
If rsProcessing.RecordCount >= 1 Then
rsSpecialists.MoveFirst
rsProcessing.MoveFirst
DoCmd.SetWarnings False
Do While Not rsProcessing.EOF
'Update records
strSQL = "UPDATE tbl_AL3_unsuccessful SET Specialist = '" & rsSpecialists.Fields("Specialist") & _
"' WHERE Specialist IS NULL" & _
" and POLICY NUMBER = " & rsProcessing.Fields("POLICY NUMBER")
'FIELD REFERENCED IN LINE ABOVE MUST BE NUMBER FORMAT
DoCmd.RunSQL (strSQL)
rsProcessing.MoveNext
rsSpecialists.MoveNext
If (rsSpecialists.EOF) Then
rsSpecialists.MoveFirst
End If
Loop
RR_assignAL3_unsuccessful = True
End If
Exit_RR_assignAL3_unsuccessful:
DoCmd.SetWarnings True
Set db = Nothing
Set rsSpecialists = Nothing
Set rsProcessing = Nothing
Exit Function
Err_RR_assignAL3_unsuccessful:
If Err.Number = 2501 Then
Resume Next
Else
MsgBox Err.Description, _
vbCritical, "<<<<Error....>>>>>"
Resume Exit_RR_assignAL3_unsuccessful
End If
End Function
Line 40 is causing a Run-time error 3075: Syntax error (missing operator in query expression).
Code:
" and POLICY NUMBER = " & rsProcessing.Fields("POLICY NUMBER")
The field referenced in line 40 is what determines when to assign multiple records to the same specialist (rather than assigning to the next specialist). Usually I use a field with a numeric value and it works fine. In this case, the assignment needs to be based by the POLICY NUMBER field, which is a text field.
Does anyone know how I can change the syntax for that line to work with POLICY NUMBER being a text field? I can't convert it to number because it is alpha-numeric.
Thanks,
Don