MS Access Need Help With Query Criteria and Weekday Function Showing Last Wednesday To This Last Tuesday

I am needing some help with the Weekday function in a query criteria. I have never used it so I don't have much experience. I am working on a payroll system currently.

The idea here is to pay the employees on Fridays.  The paycheck will consist of the days Wednesday until Tuesday. Then the employee receives the check on that following Friday.

I am having trouble understanding how to put this together. I thank you for help.
Dustin StanleyEntrepreneurAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gustav BrockCIOCommented:
You can find the previous Tuesday and Wednesday using this function:

' Returns the date of the weekday as specified by DayOfWeek
' before Date1.
'   2016-01-13. Gustav Brock, Cactus Data ApS, CPH.
Public Function DatePreviousWeekday( _
    ByVal Date1 As Date, _
    Optional ByVal DayOfWeek As VbDayOfWeek = vbUseSystemDayOfWeek) _
    As Date

    Dim ResultDate  As Date
    If DayOfWeek = vbUseSystemDayOfWeek Then
        DayOfWeek = Weekday(Date1)
    End If
    ResultDate = DateAdd("d", 1 - Weekday(Date1, DayOfWeek), Date1)
    DatePreviousWeekday = ResultDate
End Function

Open in new window


FromWednesday = DateAdd("w", -1, DatePreviousWeekday(Date, vbWednesday))
ToTuesday = DatePreviousWeekday(Date, vbTuesday)

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dustin StanleyEntrepreneurAuthor Commented:
Thank you Gustav. I will try this in the morning. Have a great night!
Dustin StanleyEntrepreneurAuthor Commented:
THANK YOU! This worked perfectly. I did have a small issue with the dates so I used in my query:

Between DateAdd("d",-7,DatePreviousWeekday(Date(),4)) And DatePreviousWeekday(Date(),4)
Gustav BrockCIOCommented:
Yes, the constants are not known in SQL.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.