title: nested do while not .eof loop based on select query access vba
body: <p>I am basically trying to convert vertical data to horizontal (like an excel table) an am almost there. I have to use a nested loop but not sure how to go about it! Here's the code so far which is working but not how I want:   </p>
  
  <pre><code>strSQL = "SELECT * FROM tblTimeSheetData WHERE [WorkDate] BETWEEN #" &amp; 
  StartDate &amp; "# AND #" &amp; EndDate &amp; "#" _ 
    &amp; "ORDER BY [EmpID], [WorkDate] ;"    
  
  Set rstTime = CurrentDb.OpenRecordset(strSQL)   
  
  Do While Not rstTime.EOF    
      rstTemp.AddNew
      lngEmpID = rstTime![EmpID]
      rstTemp![EmpID] = lngEmpID
  
      intWeekday = Weekday(rstTime![WorkDate])
  
      Select Case intWeekday
  
          Case 2
             rstTemp![MondayWorkDate] = rstTime![WorkDate]
             rstTemp![MondayWorkHours] = rstTime![WorkHours]
  
          Case 3
             rstTemp![TuesdayWorkDate] = rstTime![WorkDate]
             rstTemp![TuesdayWorkHours] = rstTime![WorkHours]
  
          Case 4
             rstTemp![WednesdayWorkDate] = rstTime![WorkDate]
             rstTemp![WednesdayWorkHours] = rstTime![WorkHours]
  
          Case 5
             rstTemp![ThursdayWorkDate] = rstTime![WorkDate]
             rstTemp![ThursdayWorkHours] = rstTime![WorkHours]
  
          Case 6
             rstTemp![FridayWorkDate] = rstTime![WorkDate]
             rstTemp![FridayWorkHours] = rstTime![WorkHours]
  
       End Select
  
       rstTemp.Update
       rstTime.MoveNext
    Loop
  </code></pre>
  
  <p>My select query returns exactly what I want:
  <a href="https://i.stack.imgur.com/TNgef.jpg" rel="nofollow noreferrer">Select query result</a></p>
  
  <p>My code returns this:
  <a href="https://i.stack.imgur.com/Wfxe8.jpg" rel="nofollow noreferrer">Code result</a></p>
  
  <p>I want it to return this:
  <a href="https://i.stack.imgur.com/vlmt2.jpg" rel="nofollow noreferrer">Horizontal view</a></p>
  
  <p>Thank you.
  AG</p>