473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Field Name Confusing in Business Days Function.

Jerry Maiapu
259 100+
Ok, I found a function that calculates/count business days excluding Weekends and holidays on the net.

My country's Holiday dates are in a table tblHolidays with fields. HolidayID,HolidayDate,HolidayName.
The Function:

Expand|Select|Wrap|Line Numbers
  1. Public Function WorkingDays(StartDate As Date, EndDate As Date) As Integer
  2. '-- Return the number of WorkingDays between StartDate and EndDate
  3. On Error GoTo err_workingDays
  4.  
  5. Dim intCount As Integer
  6.  
  7. If IsDate(StartDate) And IsDate(EndDate) Then
  8.    If EndDate >= StartDate Then
  9.  
  10.       intCount = 0
  11.       Do While StartDate < EndDate
  12.          StartDate = StartDate + 1
  13.  
  14.             If Weekday(StartDate, vbMonday) <= 5 And _
  15.             IsNull(DLookup("[Holiday]", "tblHolidays", _
  16.             "[HolDate] = " & Format(StartDate, "\#mm\/dd\/yyyy\#;;;\N\u\l\l"))) Then
  17.  
  18.             intCount = intCount + 1
  19.          End If
  20.       Loop
  21.       WorkingDays = intCount
  22.    Else
  23.       WorkingDays = -1  '-- To show an error
  24.    End If
  25. Else
  26.    WorkingDays = -1  '-- To show an error
  27. End If
  28.  
  29. exit_workingDays:
  30.    Exit Function
  31.  
  32. err_workingDays:
  33.    MsgBox "Error No:    " & Err.Number & vbCr & _
  34.    "Description: " & Err.Description
  35.    Resume exit_workingDays
  36.  
  37. End Function
Now I need to replace the field name Holiday in code line#15 with my table's field names. I know for sure that I should replace[b]HolDate [/B with HolidayDate but for Holiday I am quite confused would it be HolidayDate or HolidayID.
Can someone figure this out? Or is it another field that I need to create? I know this is simple for some people but please help.

Thanks
Jul 22 '10 #1

✓ answered by RuralGuy

Two changes:
Expand|Select|Wrap|Line Numbers
  1. If Weekday(StartDate, vbMonday) <= 5 And _ 
  2.    IsNull(DLookup("[HolidayDate]", "tblHolidays", _ 
  3.             "[HolidayDate] = " & Format(StartDate, "\#mm\/dd\/yyyy\#;;;\N\u\l\l"))) Then

7 1754
RuralGuy
375 Expert 256MB
Two changes:
Expand|Select|Wrap|Line Numbers
  1. If Weekday(StartDate, vbMonday) <= 5 And _ 
  2.    IsNull(DLookup("[HolidayDate]", "tblHolidays", _ 
  3.             "[HolidayDate] = " & Format(StartDate, "\#mm\/dd\/yyyy\#;;;\N\u\l\l"))) Then
Jul 25 '10 #2
NeoPa
32,556 Expert Mod 16PB
I doubt it matters very much Jerry in fact. As it's only being tested for Null anyway, it's not the field that's important, but whether or not the record exists. If the record exists I doubt either field would contain a Null (which is the only thing that might confuse the issue).

PS. Please be careful with your titles. Field & Filed have thoroughly different meanings.
Jul 25 '10 #3
Jerry Maiapu
259 100+
Thanks for the replies ..Now I can figure out how easy it was after your posts.
Jul 26 '10 #4
RuralGuy
375 Expert 256MB
Glad we could help.
Jul 26 '10 #5
Jerry Maiapu
259 100+
Neo, Thanks for choosing my best answer..My internet suddenly dropped after the reply so I could not choose the BAnswer.

Cheers
Jul 27 '10 #6
NeoPa
32,556 Expert Mod 16PB
I think possibly you tried and it worked, even though you weren't able to see it. I certainly didn't select it, though I would have been happy to do it for you if you'd asked me to for any reason.
Jul 27 '10 #7
Jerry Maiapu
259 100+
@NeoPa
Wow, my fault maybe I did,,you're correct. You figure out things quickly so I thought you did.

In my side of the world we have a inconsistent zig zag type network here that drops and picks up quite too often so sometimes I do not have the time to really go through things thoroughly.. You know it is typical of developing nations..

But thanks again for most of the assistance anyway,

Best regards

Jerry
Jul 27 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: David Stockwell | last post by:
I''m wondering if the Calendar object has an option to only do calculations based on business days (ie M-F). Additionally does it have a way to get holidays into itself? Currently I'm...
12
by: Anthony Robinson | last post by:
Is anyone aware of a function (system or user defined) that will calculate business days? For instance: I have a column in as table called DATE. I want to be able to add five business days to that...
1
by: igendreau | last post by:
I have users inputting a "Request Date". Upon entering a date, I need Access to populate a second field ("Due Date"). When they enter their Request Date, I want Access to set the default value of...
4
by: CDMAPoster | last post by:
I'm starting to come up with a version of DateAdd that I call BusinessDateAdd that adds the selected number of business days. It's still in preliminary form (needs testing) and interacts with my...
7
by: Sam | last post by:
Hi, I use C# in my ASP.NET projects. Here's what I need to do: I want to add x business days to a given date i.e. add 12 business days to today's date. What is the best, fastest and most...
1
by: LisaY | last post by:
I have a date listed in one cell and I want to subtract 3 business days from that date excluding holidays. Does anyone know how that would be done? Will "NETWORKDAY" function work?
8
by: =?Utf-8?B?QWw=?= | last post by:
I am working in vb2005. how can I calculate business days (not including holidays and weekends) between 2 dates? thanks Al
1
by: ArchMichael | last post by:
i need help again on calculating business days excluding holidays i have a field called assign date and i need to calculate 7 business days excluding holidays ( already have a table for holiday)...
5
FishVal
by: FishVal | last post by:
IMHO, the following is not a how-to-do instruction to solve a particular problem but more a concept-proof stuff demonstrating possibilities of SQL. So, let us say the problem is to calculate...
1
by: chevyas123 | last post by:
How do i write a function to calculate business days excluding weekends and holidays in oracle? Actually i need to prepare a calendar for my monthly activities i.e activity x to be performed on 3rd...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.