I am attempting to round-robin names into a “TASK” column depending on which type of job is assigned in the “JOB” column. My table looks like this for example:

my code is as follows:
Sub macro2()
Dim Rst As DAO.Recordset
Set Rst = CurrentDb.OpenRecordset("table1")
Dim employee(2) As String
employee(0) = "empname1"
employee(1) = "empname2"
Dim i As Integer
With Rst
i = 0
Rst.MoveFirst
Do While Not .EOF
If Rst.Fields("JOB") = "LETTER" Then
Rst.Edit
Rst.Fields("Task").value = employee(i)
Rst.Update
End If
.MoveNext
i = i + 1
If i > 2 Then i = 0
Loop
End With
DoCmd.Requery
End Sub
The problem is, sometimes it “misses” an assignment, and I am not sure why.

It should have kept looping those 2 names into the column, but it wont. However, sometimes after running it a couple of times it will do it. Upon opening the DB fresh, it will not, and will appear as above after completing. Any ideas?
This piece of the code allows
ito have a value of 2.But
UBound(employee)is 1, which meansemployee(i)should throw a “subscript out of range” error wheniis 2. But you didn’t report getting that error, so I don’t understand what’s going on.Also your first screenshot shows “Letter” and “Change” in the Job column, but the second screenshot shows all as “Letter”. That’s another puzzler.
Maybe you need to load the recordset with a query rather than the full table.
Then as you move through the recordset rows, toggle
ibetween 0 and 1.It looks to me like those changes might allow your code to work as you intend. However consider an approach which is more flexible and easier to maintain. Store the employee names in a table and open a second recordset, rsEmployees, to hold those employee names. As you move through the first recordset, Rst, also advance the second:
rsEmployees.MoveNextIf you reachrsEmployees.EOF, dorsEmployees.MoveFirstThat should “round robin” the assignments.That approach would allow you to add/remove employees from the available pool by simply updating the employees table. You wouldn’t need to revise your VBA code each time you add/remove employees.