Larry Brister
asked on
MS Access 2003 VBA Function
I need to create a function in MS Access 2003 VBA code that
I pass in a Yes or No
If Yes it returns a date calculated from the previous saturday + 13
If No then it returns a date calculated from previous saturday + 6 days.
I pass in a Yes or No
If Yes it returns a date calculated from the previous saturday + 13
If No then it returns a date calculated from previous saturday + 6 days.
Is this a homework assignment?
To get the "previous saturday", I assume you mean from the current date, use a combination of the dateadd and weekday functions.
?dateadd("d", -weekday(date(), vbSunday), date())
You should be able to take it from there.
?dateadd("d", -weekday(date(), vbSunday), date())
You should be able to take it from there.
ASKER
fyed...
NO it is not a homework assignment.
I'm busy and I use EE as a resource.
This is for a hours entry "pay period" function.
Is what I have here a problem?
I modified it with your code and it ran with same results.
I'm calculating next time person gets paid based on current day (previous Saturday) hours entry using a "lag" or paid behind period.
NO it is not a homework assignment.
I'm busy and I use EE as a resource.
This is for a hours entry "pay period" function.
Is what I have here a problem?
I modified it with your code and it ran with same results.
Private Function FindPayDate(ByVal lag As String) As Date
If lag = "Yes" Then
FindPayDate = (Now() - 7) + (7 - Weekday(Now())) + 13
Else
FindPayDate = (Now() - 7) + (7 - Weekday(Now())) + 6
End If
End Function
I'm calculating next time person gets paid based on current day (previous Saturday) hours entry using a "lag" or paid behind period.
What do you want to see?
Your function returns 2/15/2013 10:15:02 AM or
2/8/2013 10:17:32 AM
Your function returns 2/15/2013 10:15:02 AM or
2/8/2013 10:17:32 AM
If you are trying to get only date, change any reference to now() to date().
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works great. Thanks