473,385 Members | 1,655 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,385 software developers and data experts.

add working days in access 2007

Ok, so I've seen this question asked before but I cant seem to adapt the solution/s provided to my particular case.

I have to record the date an item goes out to a suncontractor, and the date it comes back in, and compare these dates to the due date to give an idea whether the subcons are giving appropriate service.
So far so good.

I have my subcontractors listed in a seperate linked table next to the lead times for each one. This lead time autopopulates on the data entry form and is added to the Outgoing date to give a Due date that I may compare to the In date.

Now in principle this is quite simple, and I have done this, but heres the problem...

The lead times are in working days, ie; monday to friday, so what I want is
1) the Due date to be calculated based only on working days,
and 2) for the due date to only fall on a working day during the week (if possible).

example; If a job goes out on a tuesday, and has a lead time of 5 days, then instead of giving the Due date to be Sunday and counting the job late when it comes in on Monday, the due date should be the following Tuesday, and the job is in fact on time.

I have everything else running very smoothly atm, and this is the final thing thats driving me wild!

Any help that anyone could give would be greatly appreciated, I can't believe this isnt a built in function to Access!
Sep 7 '11 #1

✓ answered by NeoPa

No need to apologise. The most important thing for me is clarity of communication and the member's current ability is almost irrelevant.

I'm still not absolutely clear where you want to call this from, but regardless of where that is you simply use the coding :
Expand|Select|Wrap|Line Numbers
  1. MoveWD([YourDate], X)
[YourDate] is used in the example as a field from your record source, but could be used in code with a Date variable or any expression that resolves to a valid date.
X can be an integer value or variable. This can even be a field from your record source if run within a SQL query.

If you try this out and find it doesn't work for any reason then post what you have tried and we'll see if we can find and fix the problem for you.

To get the code into a usable state in your project you need to paste it into a Standard Module in your project. If your project doesn't yet have one, or you choose to enter it into a new one anyway, then do the following (New or existing you should read Require Variable Declaration first) :
  1. Open/Switch to the VBA IDE (Code development window) using Alt-F11 from Access.
  2. Make sure the Project Explorer pane is open and selected (Ctrl-R).
  3. Navigate the tree and see if a Modules branch exists.
    At this point you can find any existing Standard Modules that already exist.
  4. We are creating a new one so the next step is to right-click with the mouse within this (Project Explorer) pane and select Insert and Module.
  5. You should now have a stub open looking like :
    Expand|Select|Wrap|Line Numbers
    1. Option Compare Database
    2. Option Explicit
  6. Paste the code for MoveWD() into this module and save it. It should prompt you for a module name so assign it one. I normally use the form modXXX so any references to it anywhere in code are easier to recognise and understand (They're clearly dealing with a module object).

5 3855
NeoPa
32,556 Expert Mod 16PB
Dav Pea:
I can't believe this isnt a built in function to Access!
It is, but we'll get to that.

Let's start from the beginning and get things properly specified before looking for solutions. Can you confirm, before we go any further with this, that weekend dates are the only dates that need to be excluded in the logic. If so then it's relatively straightforward. If not then it's a whole different ball game.

Assuming for now then, that we have the question right and there are no requirements to avoid special holiday dates etc, then there is a built-in facility to handle this for you. Unfortunately, it doesn't work! Caveat: It hasn't worked in any version I've tested it on, but I wrote my own routine to handle it so don't test it regularly.

DateAdd() has an option to move backwards or forwards by weekdays (DateAdd("w",1,Date())). I just checked it in Access 2003 by running the following code from the Immediate Pane :
Expand|Select|Wrap|Line Numbers
  1. For X = 1 To 6 : ?DateAdd("w",X,Date()) : Next X
  2. 08/09/2011
  3. 09/09/2011
  4. 10/09/2011
  5. 11/09/2011
  6. 12/09/2011
  7. 13/09/2011
The results show that weekend dates were included with all the others :-(

The MoveWD() function was developed to provide this functionality.

Expand|Select|Wrap|Line Numbers
  1. 'MoveWD moves datThis on by the intInc weekdays.
  2. Public Function MoveWD(datThis As Date, intInc As Integer) As Date
  3.     MoveWD = datThis
  4.     For intInc = intInc To Sgn(intInc) Step -Sgn(intInc)
  5.         MoveWD = MoveWD + Sgn(intInc)
  6.         Do While (Weekday(MoveWD) Mod 7) < 2
  7.             MoveWD = MoveWD + Sgn(intInc)
  8.         Loop
  9.     Next intInc
  10. End Function
Sep 7 '11 #2
Ah right... now firstly thank you very much for a quick response, I didn't expect that!

I feel a bit dense in saying i'm not quite sure in how to go about implementing that solution. I can confirm that I only need weekends excluded, i'd rather not open the can of worms that is holidays and our business runs most holidays anyway.

How would I go about using that code? In particular I need it to get a lead time from a table, which it can reference, and then add said lead time to the date autopopulated on the form, to give the due date. Everything I know about VBA I learned on the fly while doing this project, which is to say I know very little!

So far my interim solution is to just add 2 days on for every 5 days of lead time, in order to give a worst case scenario of lateness, but obviously this isnt ideal.

I apologize for asking for clarification, you have most likely fixed my problem, I am just not sure of how to implement the solution!

Thanks again.
Sep 8 '11 #3
NeoPa
32,556 Expert Mod 16PB
No need to apologise. The most important thing for me is clarity of communication and the member's current ability is almost irrelevant.

I'm still not absolutely clear where you want to call this from, but regardless of where that is you simply use the coding :
Expand|Select|Wrap|Line Numbers
  1. MoveWD([YourDate], X)
[YourDate] is used in the example as a field from your record source, but could be used in code with a Date variable or any expression that resolves to a valid date.
X can be an integer value or variable. This can even be a field from your record source if run within a SQL query.

If you try this out and find it doesn't work for any reason then post what you have tried and we'll see if we can find and fix the problem for you.

To get the code into a usable state in your project you need to paste it into a Standard Module in your project. If your project doesn't yet have one, or you choose to enter it into a new one anyway, then do the following (New or existing you should read Require Variable Declaration first) :
  1. Open/Switch to the VBA IDE (Code development window) using Alt-F11 from Access.
  2. Make sure the Project Explorer pane is open and selected (Ctrl-R).
  3. Navigate the tree and see if a Modules branch exists.
    At this point you can find any existing Standard Modules that already exist.
  4. We are creating a new one so the next step is to right-click with the mouse within this (Project Explorer) pane and select Insert and Module.
  5. You should now have a stub open looking like :
    Expand|Select|Wrap|Line Numbers
    1. Option Compare Database
    2. Option Explicit
  6. Paste the code for MoveWD() into this module and save it. It should prompt you for a module name so assign it one. I normally use the form modXXX so any references to it anywhere in code are easier to recognise and understand (They're clearly dealing with a module object).
Sep 8 '11 #4
It's....it's so beautiful. Works perfectly. I cannot thank you enough, been getting really frustrated over this, and to have it work so well just like that has really cheered me up!

You guys really aren't getting enough credit, that was clear and concise.

Again, many thanks for a speedy resolution!
Sep 9 '11 #5
NeoPa
32,556 Expert Mod 16PB
It's a pleasure to help Dav. Hopefully others in a similar position will find it equally helpful :-)
Sep 9 '11 #6

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

Similar topics

7
by: denuk2003 | last post by:
Hi Everybody I have a 2003 application that I am trying to run under 2007, The code seems to work OK but the Ribbon is a big problem. It just takes up too much space away from the application. ...
0
by: kumarkanth | last post by:
My question is how do I manipulate the procedure to calculate cut-off date with in working days and it should skip weekends and holidays? I have holiday table to determine holidays Table Name :...
16
by: Neil | last post by:
I posted a few days ago that it seems to me that the Access 2007 rich text feature does not support: a) full text justification; b) programmatic manipulation. I was hoping that someone might...
9
by: prakashwadhwani | last post by:
Hi !! I'm about to develop a new project for a client. Should I go about it in Access 2003 or 2007 ? Purchasing it either for me or for my client is not a major consideration here ... what I'd...
0
by: musicloverlch | last post by:
I have a database called RADB.mdb. I am working in Access 2007, but have to create a db in Access 2000 as some users don't have Access 2007. Everytime I setup an ODBC link in my database, Access...
8
by: jerken | last post by:
Im working in Access 2007 using two Combo boxes to select a category then product type. I am trying to get a couple fields to be displayed based on what the values are in the combo boxes. I have the...
2
by: HSXWillH | last post by:
I'm working in Access 2007 and coming to something that's always caused me problems. I have a form titled frmUsers. There are 3 subforms that list exercise dates and exercise types for each user. ...
2
by: David Anderson | last post by:
I recently began working with Access 2007, but I do have a limited experience with prior versions. I have a form with a button whose visibility I would like to make conditional on the Month value...
6
by: jenniferhelen | last post by:
I am working in Access 2007 and trying to import a .csv file. One of the fields in the .csv file, called Locations, contains numbers with leading zeros and also the last record contains letters. I...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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
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...

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.