473,402 Members | 2,046 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,402 software developers and data experts.

DateAdd exclude Weekends

10
I know this is a 'dead horse' here however, I've searched this site and still can't get it right...

I have a field named [court_date] and a field named [serve_by]. The [served_by] date has to be 7 working days before the [court date].

I copied and pasted the following function from this site:
Expand|Select|Wrap|Line Numbers
  1. '********************************************************** 
  2. 'Declarations section of the module 
  3. '********************************************************** 
  4.  
  5. Option Explicit 
  6.  
  7. '========================================================== 
  8. ' The DateAddW() function provides a workday substitute 
  9. ' for DateAdd("w", number, date). This function performs 
  10. ' error checking and ignores fractional Interval values. 
  11. '========================================================== 
  12. Function DateAddW (ByVal TheDate, ByVal Interval) 
  13.  
  14.    Dim Weeks As Long, OddDays As Long, Temp As String 
  15.  
  16.    If VarType(TheDate) <> 7 Or VarType(Interval) < 2 Or _ 
  17.               VarType(Interval)  > 5 Then 
  18.       DateAddW = TheDate 
  19.    ElseIf Interval = 0 Then 
  20.       DateAddW = TheDate 
  21.    ElseIf Interval > 0 Then 
  22.       Interval = Int(Interval) 
  23.  
  24.    ' Make sure TheDate is a workday (round down). 
  25.  
  26.       Temp = Format(TheDate, "ddd") 
  27.       If Temp = "Sun" Then 
  28.          TheDate = TheDate - 2 
  29.       ElseIf Temp = "Sat" Then 
  30.          TheDate = TheDate - 1 
  31.       End If 
  32.  
  33.    ' Calculate Weeks and OddDays. 
  34.  
  35.       Weeks = Int(Interval / 5) 
  36.       OddDays = Interval - (Weeks * 5) 
  37.       TheDate = TheDate + (Weeks * 7) 
  38.  
  39.   ' Take OddDays weekend into account. 
  40.  
  41.       If (DatePart("w", TheDate) + OddDays) > 6 Then 
  42.          TheDate = TheDate + OddDays + 2 
  43.       Else 
  44.          TheDate = TheDate + OddDays 
  45.       End If 
  46.  
  47.       DateAddW = TheDate 
  48. Else                         ' Interval is < 0 
  49.       Interval = Int(-Interval) ' Make positive & subtract later. 
  50.  
  51.    ' Make sure TheDate is a workday (round up). 
  52.  
  53.       Temp = Format(TheDate, "ddd") 
  54.       If Temp = "Sun" Then 
  55.          TheDate = TheDate + 1 
  56.       ElseIf Temp = "Sat" Then 
  57.          TheDate = TheDate + 2 
  58.       End If 
  59.  
  60.    ' Calculate Weeks and OddDays. 
  61.  
  62.       Weeks = Int(Interval / 5) 
  63.       OddDays = Interval - (Weeks * 5) 
  64.       TheDate = TheDate - (Weeks * 7) 
  65.  
  66.    ' Take OddDays weekend into account. 
  67.  
  68.       If (DatePart("w", TheDate) - OddDays) > 2 Then 
  69.          TheDate = TheDate - OddDays - 2 
  70.       Else 
  71.          TheDate = TheDate - OddDays 
  72.       End If 
  73.  
  74.       DateAddW = TheDate 
  75.     End If 
  76.  
  77. End Function
However, I can't get it to work.

When I put in the code:
Expand|Select|Wrap|Line Numbers
  1. Serve_by= DateAddW ("d", -7, [court_date])
I get "Complie Error: Wrong Number of Arguments or Invalid Property Assignments"

When I put in the code:
Expand|Select|Wrap|Line Numbers
  1. Serve_by= DateAddW(-7, [Court_date])
It returns "01/01/2010"

What am I doing Wrong?
Oct 25 '09 #1
5 6469
nico5038
3,080 Expert 2GB
You should use:
DateAddW( [Court_date], -7)
as the function has two arguments:
TheDate AND Interval

Nic;o)
Oct 25 '09 #2
Shaft11
10
Thank you for your reply,

However, It seems that the function is counting 7 weeks, not 7 days. Is there something that I need to change in the function or the code?
Oct 26 '09 #3
NeoPa
32,556 Expert Mod 16PB
It's a function to move a number of weeks.

Check out Function to Move (Forwards or Backwards) Through Weekdays instead.
Oct 26 '09 #4
Shaft11
10
How do I call the function?
Oct 26 '09 #5
NeoPa
32,556 Expert Mod 16PB
Expand|Select|Wrap|Line Numbers
  1. RequiredDate = MoveWD(datThis:=OriginalDate, intInc:=NoOfWDays)
Oct 26 '09 #6

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

Similar topics

1
by: Raghu | last post by:
Hello... I am running into a problem while running a query..can some1 help.. this is the query : ************** SELECT * from Table S where S.dtDate1 BETWEEN...
1
by: PMBragg | last post by:
ORINGINAL Post >Thank you in advance. I'm trying to pull all inventory items from December >of the previous year back to 4 years for my accountant. I know this can be >done, but I'm drawing a...
3
by: Annette Massie | last post by:
I am trying to insert a record into a table via code and one of the values to add I would like as a dateadd calculation on a value from a query. My code looks like this: Set db = CurrentDb() ...
4
by: ey.markov | last post by:
Greetings, I have an A2K application where for a report the user enters a month-end date, and the system must gather transactions for that month. No problem, I thought, I'll just use the DateAdd...
2
by: Rich Raffenetti | last post by:
I have the following code. If I do the dateadd function with dateinterval.minute, it works fine and the date/time value is displayed with zero seconds. If I do the dateadd function with...
2
by: rajeevs | last post by:
Hi I been away for sometime. Pls help me with my new problem i need to do a leave calculation using a text box. I have a start date (date format) and number of days(number). The calculation i...
0
by: Trent Nelson | last post by:
Following on from the success of previous sprint/bugfix weekends and sprinting efforts at PyCon 2008, I'd like to propose the next two Global Python Sprint Weekends take place on the following...
0
by: Michael Foord | last post by:
Trent Nelson wrote: I should be able to help organise and attend the London contribution. Personally I'd like to work on the documentation changes / clean-up for the unittest module discussed...
3
by: Mel | last post by:
When I use the DateAdd function using "DateInterval.Weekday" it does not return the correct date, well at least how I thought the weekday option should work. It is counting weekends and I only...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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
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...
0
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...
0
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...

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.