Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9268051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:42:37+00:00 2026-06-18T14:42:37+00:00

I am attempting to round-robin names into a TASK column depending on which type

  • 0

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:

example table

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.

table pic did not pull

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:42:38+00:00Added an answer on June 18, 2026 at 2:42 pm

    This piece of the code allows i to have a value of 2.

    i = i + 1
    If i > 2 Then i = 0
    

    But UBound(employee) is 1, which means employee(i) should throw a “subscript out of range” error when i is 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.

    Set Rst = CurrentDb.OpenRecordset("SELECT Job, Task FROM table1 " & _
        "WHERE Job = 'Letter'")
    

    Then as you move through the recordset rows, toggle i between 0 and 1.

    i = IIf(i = 1, 0, 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.MoveNext If you reach rsEmployees.EOF, do rsEmployees.MoveFirst That 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Attempting to insert an escape character into a table results in a warning. For
I'm attempting to create a method which will round nullables to a given decimal
Attempting to build a C# NPAPI plugin I have found a tutorial which describes
Attempting to use XStream's JavaBeanConverter and running into an issue. Most likely I'm missng
Attempting to build a C# project which has numerous references to assemblies in NuGet
I'm attempting to store the value 0.9999 into an mpfr_t variable using the mpfr_set_str()
We are attempting to use VS2008 Class Designer for a UML-like class diagram. However,
Attempting something like public string MyText { get {return lbl.Text;} set {lbl.Text = value;}}
Ok I am attempting to round my corners via CSS so I can drop
Attempting to better understand chaining on a hashtable. Seeking a simple table that hashes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.