473,765 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Counting Days in Access

Help..please!

I'm a rookie in terms of VB, but I'm desperately trying to make Access
count the number of days between two dates and then subtract the
weekends. Can anyone tell me what is wrong with the follwing code:

Option Compare Database

Public Function WorkingDays(Sta rtDate As Date, EndDate As Date) As
Integer

On Error GoTo Err_WorkingDays

Dim intCountA As Integer

If StartDate Is Empty Then
intCountA = 0
Else

intCountA = 0
Do While StartDate <= EndDate
Select Case Weekday(StartDa te)
Case Is = 1, 7
intCountA = intCountA
Case Is = 2, 3, 4, 5, 6
intCountA = intCountA + 1
End Select
StartDate = StartDate + 1
Loop

WorkingDays = intCountA

Exit_WorkingDay s:
Exit Function

Err_WorkingDays :
Select Case Err

Case Else
MsgBox Err.Description
Resume Exit_WorkingDay s
End Select

End Function

Feb 27 '06 #1
2 2208
I haven't tried to analyze your code, but it apparently doesn't take
holidays into account. A solution I've used includes generating an
array for dates -20 to +20 years from today leaving weekends and
holidays out. I'll share the code if you write to bi***@gci.net,
although it may take a few hours for me to extract it for you.
On 27 Feb 2006 06:05:46 -0800, "Jannick"
<ja************ ***********@hot mail.com> wrote:
Help..please !

I'm a rookie in terms of VB, but I'm desperately trying to make Access
count the number of days between two dates and then subtract the
weekends. Can anyone tell me what is wrong with the follwing code:

Option Compare Database

Public Function WorkingDays(Sta rtDate As Date, EndDate As Date) As
Integer

On Error GoTo Err_WorkingDays

Dim intCountA As Integer

If StartDate Is Empty Then
intCountA = 0
Else

intCountA = 0
Do While StartDate <= EndDate
Select Case Weekday(StartDa te)
Case Is = 1, 7
intCountA = intCountA
Case Is = 2, 3, 4, 5, 6
intCountA = intCountA + 1
End Select
StartDate = StartDate + 1
Loop

WorkingDays = intCountA

Exit_WorkingDa ys:
Exit Function

Err_WorkingDay s:
Select Case Err

Case Else
MsgBox Err.Description
Resume Exit_WorkingDay s
End Select

End Function


Feb 27 '06 #2
OTTOMH
Only variants can be empty;
An EndIf is missing;
The function counts the day started, so it may not actually return the
weekdays between (I think if one inputs a Sunday and the next Saturday
as parameters one gets 6 weekdays);
The Select Case in the Err_Working Days does nothing.

I encourage you to write your own code, and will resist the temptation
to post a function of my own.

Feb 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2640
by: stephan beal | last post by:
Good morning, C++ers, A couple days ago i came across a useful trick for counting instances of a given class, and i thought i'd pass it on: Conventionally, as described in several books, to do instance counting we subclass some base type and add a counter to that base class. IMO that is completely unnecessary: /**
6
1829
by: edwardfredriks | last post by:
I'm looking for a script that, instead of counting down, can "count up" from a given date. So the output should be something like "(xx) days since (date/event)" or "(date/event) was (xx) days ago". Does anybody know where to find a script like that, or could someone code one for me? Thanks in advance. Yours,
2
3421
by: David Mitchell | last post by:
I have tried using the following code to count the specific number of each weekday but get a compile error "User defined type not defined" which I think relates to the first line of the function: - Public Function HowManySpecificDays(StartDate As Date, EndDate As Date) As DayCounts and specifically the word "DayCounts" Can anyone help?
32
4234
by: William Stacey [MVP] | last post by:
Here is the link. If you find an issue or think of a feature, please post a reply or send an email. Cheers! http://www.mvptools.com/doco/csharp/semaphoredjikstra.htm -- William Stacey, MVP
4
4197
by: aaronfude | last post by:
Hi, Please consider the following class (it's not really my class, but it's a good example for my question): class Vector { int myN; double *myX; Vector(int n) : myN(n), myX(new double) { } double &operator()(int i) { return myX; }
21
2558
by: jennwilson | last post by:
Ok - So, I am back. I would like to count the number of times a specific record appears in a field from one table in my query and then use that value in the same query to calculate an average. I am using Access 2000 and am still learning. Background info: Overall, I am creating a database to track and calculate data regarding employee productivity. For each scheduled day, employees have a set number of points to earn. Employees...
11
1705
by: WhiteShore | last post by:
hey there all.. i have a several questions about how to displaying date by counting on days.. i get the current date, and how to display date for: 1. end of this month 2. the 15th of next month 3. 30days from the current date thank u guyz...
11
1992
by: freeflyer30339 | last post by:
I am trying to create code and or a query in Ms Access 03 to calculate the number of times a customer has purchased the same product within 7 days. Customer Product_no Pur_date Repeats A 21-22-23 6/1/2008 2 A 49-72-02 6/2/2008 0 B 17-24-04 6/1/2008 3 B 17-24-04 6/5/2008 2 A 21-22-23 6/5/2008 0 C 67-42-20 6/6/2008 0 B ...
2
2843
by: vspsdca | last post by:
Hi, I'm quite new to the world of VBA so any help you could extend will help me a lot with my project. I have a database of Change Requests from our users. I have two date boxes, one is Date Request Raised and Deadline for Entry. What I'd like to happen is when I enter the date on the Date Request Raised the Deadline for Entry would automatically be filled based on the Asset type that was selected. For example: if the asset type = 2...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9835
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5277
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.