title: VBA Do While Loop
body: <p>Good Morning,</p>
  
  <p>I am building a database that will be used for scheduling employee work assignments.  Below is the code that I am using to create the actual daily work assignments.  The intent is that this will loop through each employee in the company and if they are in a work status it will also read their assigned schedule version.  Then if the employee is in a work status the db will list their work assignments for each day.</p>
  
  <p>The issue that I am encountering is that this only reads the first employee in the table and gives every other employee the work assignments that the first employee should have.  Again, the intent is that the code will look at each employees, one at a time, and append the correct assignments to tbl_employee_work_assignments based on each employees status and schedule version.</p>
  
  <p>Can someone help me understand how to do this correctly, please?</p>
  
  <p>Many Thanks!!!</p>
  
  <pre><code>Private Sub btn_build_assignment_schedule_Click()
      Dim db As DAO.Database
      Dim rs As DAO.Recordset
  
      Set db = CurrentDb
      Set rs = db.OpenRecordset("tbl_employees")
  
      DoCmd.SetWarnings False
      DoCmd.RunSQL "DELETE * FROM tbl_employee_work_assignments"
  
      Do While Not rs.EOF
                  Dim X As String
                  Dim Y As String
                  X = employee_schedule_version.Value
                  Y = employee_status.Value
                  DoCmd.SetWarnings False
                  DoCmd.RunSQL "DELETE * FROM tbl_employee_work_assignments"
                  Select Case True
                      Case X = 1 And Y = 1
                          db.Execute "qry_append_schedule_1"
                      Case X = 2 And Y = 1
                          db.Execute "qry_append_schedule_2"
                      Case X = 3 And Y = 1
                          db.Execute "qry_append_schedule_3"
                      Case X = 4 And Y = 1
                          db.Execute "qry_append_schedule_4"
                  End Select
              rs.MoveNext
              Loop
      rs.Close
  
  End Sub
  </code></pre>