We help IT Professionals succeed at work.
Get Started

VBA Access Timesheet - Vertical to Horizontal view

andrew gunesberk
on
106 Views
Last Modified: 2017-12-22
I am basically trying to convert vertical data to horizontal (like an excel table) an am almost there. I have to use a loop but the result is not what I want and not sure how to go about it! Here's the code so far which is working but not how I want:

strSQL = "SELECT * FROM tblTimeSheetData WHERE [WorkDate] BETWEEN #" & 
StartDate & "# AND #" & EndDate & "#" _ 
  & "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

Open in new window


My select query returns exactly what I want:
TNgef1.jpg
My code returns this:
Wfxe8.jpg
I want it to return this:
vlmt2.jpg
Thank you so much for your help!
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE