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 then the Deadline for Entry would only be a day from when the request was raised. If the asset type is <> 2 then the deadline for entry would be 5 working days from the day the request was raised where the weekend days are not counted.
I saw a module for just counting the weekdays but I just dont know where and how I can use the module with the DateAdd function for the situation i mentioned above.
If you can provide me with a solution and guide me as well as to where I should put the code in (i.e., Before Update, OnClick etc.), I'd really appreciate it.
Many thanks.
2 2841 FishVal 2,653
Recognized Expert Specialist
Something like this: -
Public Function WorkDays(dteStart, dteEnd, _
-
Optional dowFirstDayOff As VbDayOfWeek = vbSaturday, _
-
Optional lngDaysOffCount As Long = 2) As Long
-
-
Dim lngDaysOff As Long
-
Dim dteFirstDayOff As Date
-
-
'calculate total days inclusively
-
WorkDays = DateDiff("d", dteStart, dteEnd) + 1
-
-
-
'subtract days off count moving [dteStart] forward [lngDaysOffCount] times
-
For i = 0 To lngDaysOffCount - 1
-
-
'find first day off date in the range
-
If Weekday(dteStart + i, dowFirstDayOff) > lngDaysOffCount Then
-
dteFirstDayOff = dteStart + i + 7 - Weekday(dteStart + i, dowFirstDayOff) + 1
-
Else
-
dteFirstDayOff = dteStart + i
-
End If
-
-
'exit in a case [dteFirstDayOff] got out of the range
-
If dteFirstDayOff + i > dteEnd Then Exit Function
-
'calculate [dteFirstDayOff] weekdays in the range and subtract from the total days
-
WorkDays = WorkDays - DateDiff("w", dteFirstDayOff + i, dteEnd) - 1
-
-
Next i
-
-
End Function
-
Regards,
Fish
FishVal 2,653
Recognized Expert Specialist
Bugfix:
Line #23 "+i" has to be removed.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: John |
last post by:
hey all..... alright, I am frusterated to the point of throwing my
machine out
the window (this board went down, trying to find stuff on google, this
has been
a nightmare) so I hope you guys can help me with a solution. This is
what I am
trying to do:
Pretty much, there are two dates in my database, a start date, and an
end
|
by: BlackFireNova |
last post by:
I need to write a report in which one part shows a count of how many
total records fall within the working days (Monday - Friday) inside of a
(prompted) given date range, in a particular geographical region.
I have written a query which prompts the user for the start and end
dates. It also filters for entries which pertain to the particular
geographical region.
I'm not sure where to go from here.
|
by: dhnriverside |
last post by:
Hi
I have a date in UK Format (dd/mm/yyyy). I want to get a series of days
after that date, but NOT Saturday or Sunday
For example, if the date is 13/12/2004 (next Monday) and I get the next 9
dates, I want to end up with a full list like.. 13, 14, 15, 16, 17, 20, 21,
22, 23, 24 (2wks, mon-fri).
How can I acheive this? (im using C#)
|
by: james |
last post by:
I have a problem that at first glance seems not that hard to figure out. But, so far, the answer has escaped me. I have an old
database file that has the date(s) stored in it as number of days.
An example is: 36,525 represents 01/01/1900. The starting point date is considered to be :
00/00/0000. I have looked thru Help and used Google and have not really found an answer.
I know that Leap Years need to be accounted for too.
Any...
|
by: clintonb |
last post by:
I'm looking for a way to calculate the number of days between two
dates using standard C++ functions.
Would it be as simple as just using the difftime() function and then
dividing that result by the number of seconds in a day?
- Clint
| |
by: =?Utf-8?B?UGF1bA==?= |
last post by:
Hi, I have a web application that I need to add 3 days to the Now day, but
need to make sure that I skip weekends and holidays. For example if Now is
friday, 3 days + now should be tuesday, counting the current day as the first
day. Now would never occure on a weekend or holiday. Anyhow just wondering
if anyone has any ideas? Thanks.
--
Paul G
Software engineer.
|
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
|
by: Mike |
last post by:
I have a routine that's calculating business days but its not counting the
weekend days that are between the start date and end date. If my start date
is 9/26/08 and my end date is 10/01/08, I should see 4 business days and 2
weekend days.
How can I get that result? I'm getting 4 business days but its not counting
the weekend days?
|
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 business days count which is defined as count of days (optionally inclusive in the current implementation) excluding weekend days and holidays.
Let us say periods to calculate are stored in table associated with contacts.
keyPeriodID -...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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...
|
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,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |