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

Calendar Work

Here is the code I have so far.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command17_Click()
  2.     Dim intHours As Double
  3.     Dim intTrial As Double
  4.  
  5.     Me.DaysGone = DateDiff("d", [LeaveDate], [ReturnDate])
  6.  
  7.     intHours = DaysGone * 8
  8.  
  9.     HoursGone = intHours
  10. End Sub
This is a Calendar Plugin that I have set up to find the difference between the two dates. The Idea is to select the first date as the day an employee left work, and have the second date as the date the employee returns to work. I am trying to figure out how to get the right amount of days, with the weekends being factored out. At the moment, if you leave on a monday and return on a monday, you are gone for 7 days. I need this to only be 5 days.

Here is a line of code that someone previously suggested:

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
This code looks like it could be useful, but my knowledge of how to implement it into my program is very limited. Perhaps there is an easier way to acomplish this? Could I use some simple math to take away 2 days from every 7 that are found with my DateDiff?

Any help is most appreciated.

Thank you
Apr 2 '07 #1
5 1450
MMcCarthy
14,534 Expert Mod 8TB
Try this ...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command17_Click()
  2.     Dim intHours As Double
  3.     Dim tmpDate As Date
  4. Dim tmpDays As Integer
  5.  
  6.    tmpDate = Me!LeaveDate
  7.    Do until tmpDate = Me!ReturnDate
  8.       If Weekday(tmpDate) NOT IN (6, 7) Then
  9.          tmpDays = tmpDays + 1
  10.       End If
  11.       tmpDate = tmpDate + 1
  12.    Loop
  13.  
  14.    Me.DaysGone = tmpDays
  15.  
  16.    intHours = DaysGone * 8
  17.  
  18.    HoursGone = intHours
  19.  
  20. End Sub
This function actually moves forward or backwards through weekdays. I don't think it's what you're looking for here.

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
Apr 2 '07 #2
Thanks so much for the help. I think this should work, but I am getting an error.

Expand|Select|Wrap|Line Numbers
  1. Do Until tmpDate = Me!ReturnDate
  2.       If Weekday(tmpDate) NOT IN (6, 7) Then
  3.          tmpDays = tmpDays + 1
The "If Weekday" line is showing up in red, and I get a syntax error. Is this because Weekday is not defined? Should "weekday" be the Box that my calendar date is put into?
Apr 4 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
Thanks so much for the help. I think this should work, but I am getting an error.

Expand|Select|Wrap|Line Numbers
  1. Do Until tmpDate = Me!ReturnDate
  2.       If Weekday(tmpDate) NOT IN (7, 1) Then
  3.          tmpDays = tmpDays + 1
The "If Weekday" line is showing up in red, and I get a syntax error. Is this because Weekday is not defined? Should "weekday" be the Box that my calendar date is put into?
Weekday() is an Access function.

Try this ... (By the way I got the 6 and 7 wrong it should have been 1 and 7)
Expand|Select|Wrap|Line Numbers
  1. If Weekday(tmpDate) <> 1 And  Weekday(tmpDate) <> 7) Then
  2.       tmpDays = tmpDays + 1
  3. End If
Mary
Apr 4 '07 #4
Woo Hoo! Much Praise to Mary. I finaly got it to work. I just had to remove the ) from the 7). Just a few touch ups and I think this small database will be ready to leave my hands.

Thanks Again.

Todd
Apr 5 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
Woo Hoo! Much Praise to Mary. I finaly got it to work. I just had to remove the ) from the 7). Just a few touch ups and I think this small database will be ready to leave my hands.

Thanks Again.

Todd
You're welcome Todd. Sorry about the closing bracket. Copying and pasting again :)

Mary
Apr 6 '07 #6

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

Similar topics

2
by: cg_news | last post by:
In short, what I am trying to do is, based on a date, calculate the week of year (as described in ISO 8601), then calculate the first and last date in this week period and return them in the format...
16
by: DFS | last post by:
If you're listening, I want the middle of the calendar (showing 1 month) to open below the cursor position. It currently opens just to the right and below the cursor position. I hunted through...
15
by: tigrfire | last post by:
I'm trying to write a program that will display the following output: MONTHLY CALENDAR This program displays a calendar. You need to provide the day of the week on which January 1 falls, and...
6
by: Jeff S | last post by:
I would like recommendations for implementing a calendar in an ASP.NET web site. My plan is to store date and event information (e.g,, "Spring Sale") in a database, and when the page is requested,...
3
by: Shevek | last post by:
Hi All, Hope someone can help! I am building an Event Calendar app based around the Calendar WebControl which builds an SQL string based on the SelectedDates property which is passed to...
0
by: R.A.M. | last post by:
Hello, I need to implement popup calendar in ASP.NET application. I created a button opening popup calendar on 'master' page: <asp:Button ID="Calendar" runat="server" Text=Calendar"...
1
by: R.A.M. | last post by:
Hello, I need to implement popup calendar in ASP.NET application. I created a button opening popup calendar on 'master' page: <asp:Button ID="Calendar" runat="server" Text=Calendar"...
1
by: xian2 | last post by:
Hi, I wanted to create a calendar in Access that would call on data stored within tables in the database (dates in forms) and would show it visually on a calendar when the calendar was opened. I...
3
by: =?Utf-8?B?UGFycm90?= | last post by:
I applied the following Ajax code in my web page which has a calendar control to keep my page from completely reloading everytime something was changed. <atlas:ScriptManager ID="ScriptManager1"...
7
by: William (Tamarside) | last post by:
Please, if you have the time and knowledge to help me I'd truly appreciate it! I need to build a calendar page that displays available/unavailable info from a DB and colour a cell according to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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$) { } ...
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...

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.