Link to home
Start Free TrialLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

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.
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

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.
Avatar of Larry Brister

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.

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

Open in new window


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
If you are trying to get only date, change any reference to now() to date().
ASKER CERTIFIED SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Works great. Thanks