Hi I'm currently 'attempting' to code something that will automatically allocate a number of records to individuals listed in a resource table. I have managed to get the code to run the allocation based on priority and role, but am struggling to limit the number of records allocated per individual.
Current code:
Sub AssignBMWorkflowC()
Dim rstResources As DAO.Recordset, rstWorkflow As DAO.Recordset
Dim strSQL As String
' Create a list of all records in tbl_Workflow where the Allocated_ID field is empty
strSQL = "SELECT * FROM tbl_Workflow WHERE Allocated_ID Is Null AND [Activity]='Outbound Call';"
Set rstWorkflow = CurrentDb.OpenRecordset(strSQL)
' Make sure there is work to assign
If rstWorkflow.RecordCount > 0 Then
rstWorkflow.MoveFirst
' Get a randomized list of all reviewers
strSQL = "SELECT * FROM [tbl_Resources] WHERE [ROLE]= 'Caller' ORDER BY Rnd([NameID]);"
Set rstResources = CurrentDb.OpenRecordset(strSQL)
' Make sure there are reviewers to assign to Calls
If rstResources.RecordCount > 0 Then
rstResources.MoveFirst
' Loop through all of the work
While Not rstWorkflow.EOF
' Assign the current reviewer to high priority work items
rstWorkflow.Edit
rstWorkflow.Fields("Allocated_ID") = rstResources.Fields("NameID")
rstWorkflow.Update
' Move to the next workitem
rstWorkflow.MoveNext
' Go to the next reviewer
On Error Resume Next
rstResources.MoveNext
On Error GoTo 0
' Re-start the list of reviewers, if necessary
If rstResources.EOF Then
rstResources.MoveFirst
End If
Wend
Else
MsgBox "There are no Callers assigned to workflow"
End If
Else
MsgBox "Error! There are no High priority Call activites in the workflow"
End If
End Sub
Appriciate any help
Current code:
Sub AssignBMWorkflowC()
Dim rstResources As DAO.Recordset, rstWorkflow As DAO.Recordset
Dim strSQL As String
' Create a list of all records in tbl_Workflow where the Allocated_ID field is empty
strSQL = "SELECT * FROM tbl_Workflow WHERE Allocated_ID Is Null AND [Activity]='Outbound Call';"
Set rstWorkflow = CurrentDb.OpenRecordset(strSQL)
' Make sure there is work to assign
If rstWorkflow.RecordCount > 0 Then
rstWorkflow.MoveFirst
' Get a randomized list of all reviewers
strSQL = "SELECT * FROM [tbl_Resources] WHERE [ROLE]= 'Caller' ORDER BY Rnd([NameID]);"
Set rstResources = CurrentDb.OpenRecordset(strSQL)
' Make sure there are reviewers to assign to Calls
If rstResources.RecordCount > 0 Then
rstResources.MoveFirst
' Loop through all of the work
While Not rstWorkflow.EOF
' Assign the current reviewer to high priority work items
rstWorkflow.Edit
rstWorkflow.Fields("Allocated_ID") = rstResources.Fields("NameID")
rstWorkflow.Update
' Move to the next workitem
rstWorkflow.MoveNext
' Go to the next reviewer
On Error Resume Next
rstResources.MoveNext
On Error GoTo 0
' Re-start the list of reviewers, if necessary
If rstResources.EOF Then
rstResources.MoveFirst
End If
Wend
Else
MsgBox "There are no Callers assigned to workflow"
End If
Else
MsgBox "Error! There are no High priority Call activites in the workflow"
End If
End Sub
Appriciate any help