Solved

MS Access 2003 VBA Function

Posted on 2013-02-04
7
562 Views
Last Modified: 2013-02-04
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.
0
Comment
Question by:lrbrister
  • 3
  • 2
  • 2
7 Comments
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 38851899
Is this a homework assignment?
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 38851906
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.
0
 

Author Comment

by:lrbrister
ID: 38851938
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.
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 26

Expert Comment

by:jerryb30
ID: 38851966
What do you want to see?
Your function returns 2/15/2013 10:15:02 AM or
2/8/2013 10:17:32 AM
0
 
LVL 26

Expert Comment

by:jerryb30
ID: 38852048
If you are trying to get only date, change any reference to now() to date().
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 38852072
Do you really want to pass a text string ("Yes", "No")

Note that I changed the return value to a variant, to accommodate a NULL value if you pass the wrong arguments.

Public Function FindPayDate(byVal lag as string) as Variant

    Dim intOffset as integer

    if lag = "Yes" Then
        intOffset = 13
    elseif lag = "No" then
        intOffset = 6
    else
         msgbox "You passed '" & lag & "'!", vbokonly, "Invalid value"
         FindPayDate = NULL
         Exit Function
    End if

    FindPayDate = dateadd("d", -weekday(date(), vbSunday), date()) + intOffset

End Function
0
 

Author Closing Comment

by:lrbrister
ID: 38852930
Works great. Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now