473,698 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Querying database for employees with X hours of sick leave

18 New Member
Could someone, anyone, help me and compose a VBA script for me to use with MS Access?

I know nothing about MS Access of VBA scripting for it but really need some help.

I have an MS Access database on a server at work that records employee sick leave, by hour, by date.

I need to know the number of occurences when employees were gone on sick leave for 10 or more consecutive work days, during a calendar year that starts on Jan 1 and ends on Dec 31.

Employees work 7.5 hours in a day, Monday to Friday, no weekends.

I was thinking I need a script that runs a check for 75 hours of sick leave in each 14 day spread during the year.

If I counted right, there should be 255 such spreads: Starting with Jan 1 to 14, then Jan 2 to 15, ... and ending with Dec 18 to 31.

If an employee is gone for 30 consecutive work days, the result should only show him once. But if he goes 10 work days, comes back to work for 5 work days, then goes for another 10 work days, the result should show him twice.

I hope this makes sense and that someone can rise to the challenge and put this together.

Thank you

Erik Lupien
Jul 15 '08
48 5620
ADezii
8,834 Recognized Expert Expert
Nice problem :-)
In a similar "find the period/gap" case I've used a + and - string to get the problem solved.

Approach:
1) Create an initial string for the whole period e.g. of 365 times the '-' character.
2) Process all records and update the day position of sick leave with a "+"
(No problem to set the same day twice or more times, just use the start and end date of each row)
3) Get the results by using INSTR(strYear," ++++++++++") and working your way through the string from left to right.

Getting the idea ?

Nic;o)
Hello Nico, I would also like to see a concrete example of your approach, since I am having trouble visualizing it also.
Jul 25 '08 #21
NeoPa
32,569 Recognized Expert Moderator MVP
Subscribing - and hopefully clarifying the last point a little.

I believe the idea, within a specific time-frame (a year for instance), is to build up a string with a character (-) in each position to indicate a normal day.
Expand|Select|Wrap|Line Numbers
  1. Dim strYear As String
  2.  
  3. strYear = String(365, "-")
The position of the character within the string is the mapping of which day in the year it represents.

Processing through the records you have for an employee, you can replace each "-" with a "+" for each day they are absent.

Simplifying for a week (strWeek starts on the Sunday), if an employee had Wednesday and Thursday off for that week, the value in strWeek (line #2) would be :
Expand|Select|Wrap|Line Numbers
  1. =SMTWTFS
  2. "---++--"
Jul 26 '08 #22
ADezii
8,834 Recognized Expert Expert
Subscribing - and hopefully clarifying the last point a little.

I believe the idea, within a specific time-frame (a year for instance), is to build up a string with a character (-) in each position to indicate a normal day.
Expand|Select|Wrap|Line Numbers
  1. Dim strYear As String
  2.  
  3. strYear = String(365, "-")
The position of the character within the string is the mapping of which day in the year it represents.

Processing through the records you have for an employee, you can replace each "-" with a "+" for each day they are absent.

Simplifying for a week (strWeek starts on the Sunday), if an employee had Wednesday and Thursday off for that week, the value in strWeek (line #2) would be :
Expand|Select|Wrap|Line Numbers
  1. =SMTWTFS
  2. "---++--"
Thanks for the clarification, NeoPa.
Jul 26 '08 #23
ADezii
8,834 Recognized Expert Expert
Hello Eric, I do believe that we are getting close to a resolution to your problem. Download the Attachment, run it against the test data provided, and against your own data, then get back to me with feedback. I won't be able to spend much more time on this Project, but I would definately like to see it concluded.
Jul 27 '08 #24
Erik Lupien
18 New Member
Hi there,

I'm sorry it's taken a while to respond.

Believe it or not, my computer is still crushing the data. It's been going at it since 9:00 a.m. last Thursday morning (July 24). My system hasn't crashed and the task manager tells me MSACESS.exe is using anywhere from 55 to 65% of my computer's CPU resources (it changes every second or so between those percentages) - so I'm guessing it's still processing the data.

Having said all this, I haven't had the opportunity to try the new code yet!

Assuming I'm not wrong on Access still processing (if someone here has something to say about it please so), I will let it continue. And as soon as it's done, I will let you know.

As for the code, I added entries to the leave 2007-2008 table to show employee 99765426 sick for the entire month of February 2008 and ran the updated script on another computer ... here's what it generated:
Expand|Select|Wrap|Line Numbers
  1. Employee          Start Date           End Date           Sick Hours         Interval#
  2. 12345678 ===> 08-10-2007 ===> 08-23-2007 =====> 67.5 =======> 145
  3. 12345678 ===> 08-16-2007 ===> 08-29-2007 =====> 67.5 =======> 151
  4. 12345678 ===> 08-18-2007 ===> 08-31-2007 =====> 67.5 =======> 153
  5. 12345678 ===> 08-20-2007 ===> 09-02-2007 =====> 67.5 =======> 155
  6. 55555555 ===> 08-08-2007 ===> 08-21-2007 =====> 75.0 =======> 143
  7. 55555555 ===> 08-10-2007 ===> 08-23-2007 =====> 67.5 =======> 145
  8. 99765426 ===> 04-01-2007 ===> 04-14-2007 =====> 67.5 =======> 001
  9. 99765426 ===> 04-01-2007 ===> 04-14-2007 =====> 67.5 =======> 001
  10. 99765426 ===> 05-08-2007 ===> 05-21-2007 =====> 60.0 =======> 038
As you can see, it didn't show employee 99765426 sick the entire month of February 2008 or at all during that month. Any idea why?

About the VBA code that could find a break in the 2-week intervals for an employee ... what do you think about the idea of creating two arrays, one with the numbers I have, and another one with the numbers expected, then looping through them and compare each value, if they aren't equal it's 'broken'. Something like this:
Expand|Select|Wrap|Line Numbers
  1. Dim i&,x&
  2. Redim arExpected(353)
  3. For i=0 to UBound(arExpected)
  4.    x=x+1:arExpected(i)=x
  5. Next
PS I will attach the updated file in the next post.

Erik
Jul 30 '08 #25
Erik Lupien
18 New Member
I cannot post an attachment! :(

Erik
Jul 30 '08 #26
nico5038
3,080 Recognized Expert Specialist
Hi Erik,

Just click on the Edit/Delete link of the comment after posting, it will allow the placement of an attachment.

I see I missed some comments from Neopa And ADezii about the +/- approach.

A small sample to show how it works for a two week period searching for 3 day's sick leave:
Input:
Expand|Select|Wrap|Line Numbers
  1. John 1/1/2008 1/5/2008
  2. John 1/9/2008 1/11/2008
Processing by creating two weeks initially in strPeriod:
Expand|Select|Wrap|Line Numbers
  1. ------------
After first row:
Expand|Select|Wrap|Line Numbers
  1. +++++---------
After second row:
Expand|Select|Wrap|Line Numbers
  1. +++++---+++---
Now using Instr(strPeriod ,"+++") will return 1 as being the first leave of three days.
To check for multiple leaves you can test:
Expand|Select|Wrap|Line Numbers
  1. IF InstrRev(strPeriod,"+++") = Instr(strPeriod,"+++")  then
  2.    ' only one found as we find the same start position
  3. else
  4.   ' multiple processing necessary
  5. endif
The multiple processing can be done using a switch between testing for "+++" and "-" (when a period in between leaves can be only one day, you could also use more by enlarging the string)
The test for the end of the period in the sample would be:
Expand|Select|Wrap|Line Numbers
  1. Instr(Instr(strPeriod,"+++"),strPeriod,"-")
This will return the value 6.
That can be used for the startpos in Instr(startpos, strPeriod,"+++" ) to find the next leave, etc..

Bit clearer ?

Nic;o)
Jul 30 '08 #27
ADezii
8,834 Recognized Expert Expert
Hi Erik,

Just click on the Edit/Delete link of the comment after posting, it will allow the placement of an attachment.

I see I missed some comments from Neopa And ADezii about the +/- approach.

A small sample to show how it works for a two week period searching for 3 day's sick leave:
Input:
Expand|Select|Wrap|Line Numbers
  1. John 1/1/2008 1/5/2008
  2. John 1/9/2008 1/11/2008
Processing by creating two weeks initially in strPeriod:
Expand|Select|Wrap|Line Numbers
  1. ------------
After first row:
Expand|Select|Wrap|Line Numbers
  1. +++++---------
After second row:
Expand|Select|Wrap|Line Numbers
  1. +++++---+++---
Now using Instr(strPeriod ,"+++") will return 1 as being the first leave of three days.
To check for multiple leaves you can test:
Expand|Select|Wrap|Line Numbers
  1. IF InstrRev(strPeriod,"+++") = Instr(strPeriod,"+++")  then
  2.    ' only one found as we find the same start position
  3. else
  4.   ' multiple processing necessary
  5. endif
The multiple processing can be done using a switch between testing for "+++" and "-" (when a period in between leaves can be only one day, you could also use more by enlarging the string)
The test for the end of the period in the sample would be:
Expand|Select|Wrap|Line Numbers
  1. Instr(Instr(strPeriod,"+++"),strPeriod,"-")
This will return the value 6.
That can be used for the startpos in Instr(startpos, strPeriod,"+++" ) to find the next leave, etc..

Bit clearer ?

Nic;o)
Excellent Tutorial Nico, thank you.
Jul 31 '08 #28
NeoPa
32,569 Recognized Expert Moderator MVP
I cannot post an attachment! :(

Erik
Let me know if this is resolved now. After posting, any post can be edited for about an hour. If you scroll down the page there is a "Manage Attachments" link. It should be fairly straightforward from there.

Also, I notice you're not using the [ CODE ] tags (the # button) in your posting generally. I can easily see that you're doing your best to be as little trouble as possible, so don't see this as criticism. Just a gentle reminder of how we like to see the posts laid out (it helps a lot to understand what's posted when it's properly laid out).

Welcome to Bytes :)
Jul 31 '08 #29
ADezii
8,834 Recognized Expert Expert
Hello Erik:
Thanks to Nico's 'String Theory' (Posts #19 and 27), there may be some light at the end of the tunnel as far as getting a resolution to your problem. When I get the chance, I'll revamp the existing code and see what happens. Worst case scenario is that we should be able to generate a list of every employee who has single/multiple, non-contiguous Sick Leaves, along with a Total Count, for the Fiscal Year. Not sure when I can get to it, but keep in touch.
Aug 1 '08 #30

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

Similar topics

3
1601
by: Eddie | last post by:
Hi to all I am building a database to track project expenses information. My database has 4 main tables, Employees, Activity, project info and rates. We add a project and track activities on the project. Each employee will add an activity on a certain date. What I need to do is check the date the activity was added and then check what the rate is that employee was paid during that period.
2
1688
by: uluvale96799 | last post by:
Hi, I'm very new to programming so forgive me for asking the dumb question. I'm trying to develop a database application using c#, and I'm using the northwind database. I'm currently using visual c# express edition 2005 as well as sql 2005 express. Here's the thing I've been trying to figure out. I want to insert a new row in the Employees Table when I click a button called btnAdd. When I was learning delphi, I would just put the...
1
1729
by: tc | last post by:
Hi. I have a customer who is running our .net application, multiple clients connecting to an Access database. This ONE customer reports a great speed degredation when more than one client is connected. First client logs on and the system runs correctly. Second client logs on, both connected clients now run very slowly when retrieving data. Third client logs on, the speed on all three clients is no degraded even more. Etc.
1
1484
by: dharnE | last post by:
I'm Hoping that this Problem will answer.The Problem is"Create A Program to compute the pay of employees as entered by the user using function statement" Sample Output: Enter Number of Employees:3 Hours:50 Rate:5.25 Pays:262.50 ------------------------------ Hours:6 Rate:5.00 Pays:30.00 ------------------------------
3
4243
by: lucky33 | last post by:
My employer has asked me to create a database that will keep track of the employee attendance. Time off / Time earned, excused / unexcused, etc. At my company from the 6th month of employment to the second year you earn 8 hours of PTO each month, from the 2nd to 4th year you earn 10 hours PTO each month. My question is how would I preform a check for each employee once a month to automatically add their newly earned PTO time?
11
5570
by: jjkeeper | last post by:
Hi, I need to create an annual leave Database for the company. I admit I was a complete novice at this. But I got thrown the job and I have to do it. So here's what I get so far, but I got pretty much stuck for some days figuring out what to do. Sorry I can't think of a better title. I have a tblMainProfile table, which stores everything about employee's particulars. ID, name, NIRC, etc etc. Next, I have tblLeaveEntitlement table, which...
1
2143
by: AllBeagle | last post by:
Hello Everyone, I'm trying to build a web-based application for a client of mine and I keep finding holes in my design, so I could use some guidance if anyone has any to offer. Let me try to explain what it is I'm trying to do and hopefully someone has an idea that's not going to take me a long time to implement and isn't above my not-so-advanced skill level. My attempts with data tables and arraylists have failed thus far. Looks like my...
3
3003
by: =?Utf-8?B?TWlrZSBDb2xsaW5z?= | last post by:
I want to allow users to search last names, using wildcards. When I try to following in my web app: //employees data was previously retrieved and stored in ViewState. var filteredData = from p in employees.ToArray() select p; filteredData = from c in employees where SqlMethods.Like(c.Username, "%" + txtSearchCriteria.Text + "%") select c;
3
8412
by: lizBeth | last post by:
Hi all, i seem to have gotten stuck on this coursework, i am unsure as to how to implement a method in the main class to calculate the sum of all employees monthly salaries. Everything else works on the program it does output the employees details and their monthly salaries. I just need to add them up and output a "Total Payroll: xxxxxx.x " in this format. It sounds simple and it probably is simple, i think i can't see the woods for...
0
8675
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9160
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, 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...
1
8897
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,...
0
8862
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7729
agi2029
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...
1
6521
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 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...
0
4370
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...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2331
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.