473,698 Members | 2,522 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 5621
ADezii
8,834 Recognized Expert Expert
Hello again, Erik, major oversight on my part. Since we changed the manner in which we determine how many Holidays occur within a specific 2 Week Interval, (multiple Boolean Fields vs. single Byte Field), the actual value is now contained in rstIntervals via rstIntervals![Holidays]. We can now extract this value directly from the Recordset as opposed to executing a DLookup() on tbl2WeekInterva ls with the criteria of [Start_Date] and [End_Date] within the Range. We should now experience a significant speed improvement, I'll run the tests and post them after I display the latest code Revisions below for Phase I:
Expand|Select|Wrap|Line Numbers
  1. Public Sub cmdTest_Click()
  2. On Error GoTo Err_cmdTest_Click
  3. Dim strSQL As String
  4. Dim MyDB As DAO.Database
  5. Dim rstUniqueEmployees As DAO.Recordset
  6. Dim rstFinalResults As DAO.Recordset
  7. Dim rstIntervals As DAO.Recordset
  8. Dim bytHolidaysInInterval As Byte
  9. Dim varTotalSickHours As Variant
  10. Dim strInterval As String
  11. Dim lngStartTime As Long
  12. Dim lngEndTime As Long
  13.  
  14. DoCmd.Hourglass True    'visual indicator of processing
  15. lngStartTime = timeGetTime()    'Start the Timer
  16.  
  17. 'Generate Unique Employee IDs in Ascending Order
  18. strSQL = "SELECT DISTINCT [LEAVE 2007-2008].PERNR FROM " & _
  19.          "[LEAVE 2007-2008]ORDER BY [LEAVE 2007-2008].PERNR;"
  20.  
  21. 'Delete all entries in the previous tblSickLeave Output Table
  22. CurrentDb.Execute "Delete * From tblSickLeave", dbFailOnError
  23.  
  24. Set MyDB = CurrentDb()      'refers to the Current Database
  25. Set rstUniqueEmployees = MyDB.OpenRecordset(strSQL, dbOpenSnapshot)
  26. Set rstIntervals = MyDB.OpenRecordset("Select * From tbl2WeekIntervals;", dbOpenSnapshot)
  27. Set rstFinalResults = MyDB.OpenRecordset("tblSickLeave", dbOpenDynaset)
  28.  
  29. 'Cross reference every Employee ([PERNR]) against every 2 week Interval ([Start_Date]/[End_Date]),
  30. 'at this intersection check the value of the [Holiday] Field (0, 1, 2, or 3), to see
  31. 'if a Holiday/Holidays occurred for the specified Interval, calculate the Total Hours [CATSHOURS]
  32. 'for each Employee/Interval. Check and see if this figure is at least 75 Hours for a No-Holiday-Interval,
  33. 'or 67.5 Hours for a single Holiday Interval, 60 Hours for a 2-Holiday Interval, or 52.5 Hours for a
  34. 'a 3-Holiday Interval.
  35. With rstUniqueEmployees     'Employees
  36.   Do While Not .EOF
  37.     Do While Not rstIntervals.EOF       '2-Week Intervals
  38.       'bytHolidaysInInterval = DLookup("[Holidays]", "tbl2WeekIntervals", "[Start_Date] = #" & _
  39.                                      'rstIntervals![Start_Date] & "# And [End_Date] = #" & _
  40.                                      'rstIntervals![End_Date] & "#")     '0,1,2, or 3 Holiday(s) in Interval?
  41.        bytHolidaysInInterval = rstIntervals![Holidays]
  42.       'Total Sick Hours for the Employee for the specified 2-Week Interval
  43.       varTotalSickHours = DSum("[CATSHOURS]", "LEAVE 2007-2008", "[WorkDate] Between #" & _
  44.                                 rstIntervals![Start_Date] & "# And #" & rstIntervals![End_Date] & _
  45.                                 "# And [PERNR] = " & ![PERNR])
  46.         If bytHolidaysInInterval = 0 Then           'NO Holiday in Interval
  47.           If varTotalSickHours >= 75 Then           'minimum of 75 hrs. for NO Holiday
  48.             strInterval = strInterval & "+"         'qualifies
  49.           Else
  50.             strInterval = strInterval & "-"         'non-qualifier
  51.           End If
  52.         ElseIf bytHolidaysInInterval = 1 Then       '1 Holidays in Interval
  53.           If varTotalSickHours >= 67.5 Then         'minimum of 67.5 hrs. for 1 Holiday
  54.             strInterval = strInterval & "+"         'qualifies
  55.           Else
  56.             strInterval = strInterval & "-"         'non-qualifier
  57.           End If
  58.         ElseIf bytHolidaysInInterval = 2 Then       '2 Holidays in Interval
  59.           If varTotalSickHours >= 60 Then           'minimum of 60 hrs. for 2 Holidays
  60.             strInterval = strInterval & "+"         'qualifies
  61.           Else
  62.             strInterval = strInterval & "-"         'non-qualifier
  63.           End If
  64.         ElseIf bytHolidaysInInterval = 3 Then       '3 Holidays in Interval
  65.           If varTotalSickHours >= 52.5 Then         'minimum of 52.5 hrs. for 3 Holidays
  66.             strInterval = strInterval & "+"         'qualifies
  67.           Else
  68.             strInterval = strInterval & "-"         'non-qualifier
  69.           End If
  70.         End If
  71.       rstIntervals.MoveNext     'Next Interval for Employee
  72.     Loop
  73.     rstFinalResults.AddNew
  74.       rstFinalResults![Employee] = ![PERNR]             'Add Employee ID
  75.       rstFinalResults![IntervalString] = strInterval    'Add concatenated Pattern String
  76.     rstFinalResults.Update
  77.  
  78.     strInterval = ""            'Reset for next Employee
  79.     rstIntervals.MoveFirst      'Move to the next 2-Week Interval
  80.     .MoveNext                   'Move to the next Employee
  81.   Loop
  82. End With
  83.  
  84. rstIntervals.Close
  85. rstUniqueEmployees.Close
  86. rstFinalResults.Close
  87. Set rstUniqueEmployees = Nothing
  88. Set rstIntervals = Nothing
  89. Set rstFinalResults = Nothing
  90.  
  91. Me![cmdFinalize].Enabled = True
  92.  
  93. lngEndTime = timeGetTime()      'End Timer (end of the line!)
  94.  
  95. Debug.Print "************ Process 1 Execution Time ************"
  96. Debug.Print "Test PC: Pentium(R) M - 1.60 GHz - 512 MB RAM"
  97. Debug.Print "Seconds: " & FormatNumber((lngEndTime - lngStartTime) / 1000, 2)
  98. Debug.Print "Minutes: " & FormatNumber(((lngEndTime - lngStartTime) / 1000) / 60, 2)
  99. Debug.Print "Hours  : " & FormatNumber((((lngEndTime - lngStartTime) / 1000) / 60) / 60, 4)
  100. Debug.Print "**************************************************"
  101.  
  102. DoCmd.Hourglass False       'indicates end of processing
  103.  
  104. Exit_cmdTest_Click:
  105.   Exit Sub
  106.  
  107. Err_cmdTest_Click:
  108.   DoCmd.Hourglass False
  109.   MsgBox Err.Description, vbExclamation, "Error in cmdTest_Click()"
  110.   Resume Exit_cmdTest_Click
  111. End Sub
  112.  
Timing Results:
Expand|Select|Wrap|Line Numbers
  1. Process    Seconds    Minutes    Hours       Records    
  2.    1    781.3     12.84        0.217     5000            
  3.    1    672.82   11.22       0.1869       5000    
P.S. - Next step, I'll run the original and revised code against the 100,000+ Records and let you know how I made out.
Aug 17 '08 #41
ADezii
8,834 Recognized Expert Expert
As one of my PCs is processing your 100,000+ Records and generating Sick Leave Data, I am looking at the overall picture, and the numbers are staggering. Here are my thoughts on the Topic:
  1. The Data set you gave me consists of 100,017 Records in the Leave 2007-2008 Table.
  2. Within these Records are 5,359 Employees with accumulated data.
  3. There are 353 distinct 2-Week Intervals for the Fiscal Year 4/1/2007 - 4/14/2007 to 3/18/2008 to 3/31/2008.
  4. Each and every Employees has to be cross-referenced against each and every 2-Week Interval. That's 1,891,727 iterations involving 2 Nested Loops, I know of no other way to accomplish this.
  5. At each juncture of Employee <==> 2-Week Interval, the following must be done:
    1. The number of Holidays within that Interval has to be determined, that info is already contained within the Recordset, so no problem there.
    2. The Total Sick Hours for each Employee per Interval has to calculated.
    3. This summation has to be compared to certain constant values depending on the Holidays occurring in that Interval.
    4. The Pattern String has to be appended to with either a '-' or "*" depending on the previous outcome.
    5. This is really an enormous, and very time consuming, undertaking.
    6. If I remember correctly, the actual Record Count that this logic would have to be performed on is in the area of 650,000 Records - staggering.
    7. With all this in mind, I would recommend the following:
      • Seek professional help, not for you of course! It seems as though this functionality is critical to your operations, so have a professional programmer look at it. He/she may come up with a completely different, and more efficient, algorithm to accomplish the same task. I have done all that I can.
      • Segment the data as you have done, breaking the Data Set into 6 - 100,000+ segments, process each, then Append the data into a Master Table.
      • Get a super fast PC, preferably the HAL 2000 from 2001 a Space Odyssey (LOL).
      • Restrict the number of 2-Week Intervals acted on, do you really need data for all 353 Intervals?
  6. Phase II, in my opinion is already optimized, and will efficiently analyze the Pattern Strings and generate the Total Sick Leave Data that you are requesting.
  7. I'll post the Timing Figures for the processing of the 100,017 Records as well as for the Phase II operations on the results of Phase I processing.
  8. For all practical purposes, once this has been accomplished, this Thread will effectively be closed.
Aug 19 '08 #42
ADezii
8,834 Recognized Expert Expert
OK, here we go Erik! I've just completed my Benchmark Tests running the revised code on the 100,017 Records in the Leave 2007-2008 Table and here are the results:
Expand|Select|Wrap|Line Numbers
  1. ************ Process 1 Execution Time ************
  2. Records:   100,017
  3. Test PC: Pentium(R) M - 1.60 GHz - 512 MB RAM
  4. Seconds:   253,358.56
  5. Minutes:     4,222.64
  6. Hours  :        70.3774
  7. Days:            2.93
  8. **************************************************
If I remember correctly, when you ran the original code against the same Data Set, it took 3.5 days with a considerably faster PC. You can interpret these results as you wish, but there seems to be at least significant improvement. In my opinion, the code in Phase 2 is already optimized and performs quite well analyzing the 5,359 Pattern Strings and outputting the Aggregate Totals. In my mind, this is not even a consideration. All good things must come to an end, and I must say that this is the end of the road as far as this Thread is concerned. I have done as much as I can with my limited skills, I can do no more. I've Attached the Optimized code with no Records in tblEvent or tblEventTemp to make sure that you are completely up to date. Good luck with your Project and let me know how you are making out from time to time.
Aug 21 '08 #43
Erik Lupien
18 New Member
Dear ADezii,

How can I thank you enough?

I am totally grateful and appreciative of the excellent work you've done.

What you put together is unlike anything my employer has seen before and the results it generates will go a tremendously long way to helping managers in my organization better identify and help employees who are absent on sick leave come back to work sooner.

Thank you, thank you, and thank you on behalf of my employer, the hundreds of managers I work for, and the thousands of employees who stand to benefit from your excellent work.

If this also doesn't seem too inappropriate, I also want to thank the owners of this site for having made this possible, and for others who contributed ... the + and - string was a wonderful solution that works beautifullly.

Erik Lupien
Aug 21 '08 #44
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi ADezii. Erik's kind words in his last post are tribute to what has been an extraordinary contribution on your part to this thread. Wonderful to read, even though going well beyond the norm in all sorts of ways...

Well done, and my goodness what a standard you set for the rest of us!

-Stewart
Aug 21 '08 #45
ADezii
8,834 Recognized Expert Expert
Hi ADezii. Erik's kind words in his last post are tribute to what has been an extraordinary contribution on your part to this thread. Wonderful to read, even though going well beyond the norm in all sorts of ways...

Well done, and my goodness what a standard you set for the rest of us!

-Stewart
Thanks Stewart for your kind words.
Aug 21 '08 #46
ADezii
8,834 Recognized Expert Expert
Dear ADezii,

How can I thank you enough?

I am totally grateful and appreciative of the excellent work you've done.

What you put together is unlike anything my employer has seen before and the results it generates will go a tremendously long way to helping managers in my organization better identify and help employees who are absent on sick leave come back to work sooner.

Thank you, thank you, and thank you on behalf of my employer, the hundreds of managers I work for, and the thousands of employees who stand to benefit from your excellent work.

If this also doesn't seem too inappropriate, I also want to thank the owners of this site for having made this possible, and for others who contributed ... the + and - string was a wonderful solution that works beautifullly.

Erik Lupien
Hello Erik, no thanks are necessary since that is why we are all here. It was a true pleasure working with you on a very challenging Project. I do have but one simple request, please keep in mind that it was Nico5038 that came up with the innovative Pattern String solution which enabled me to correctly analyze the Sick Leave Cycles. It if wasn't for Nico's code, I may have never arrived at a viable solution, or if it did, it would have been significantly delayed. We both owe a lot to him. Take care Erik.
Aug 21 '08 #47
nico5038
3,080 Recognized Expert Specialist
Don't give me too many credits ADezii, I've merely shared a concept and left the hard (coding) part to you :)

A job well done!

Nic;o)
Aug 21 '08 #48
ADezii
8,834 Recognized Expert Expert
Two closing points, Erik, and two I feel that are worth mentioning:
  1. When you are running this code, if applicable, turn OFF the following Sevices. For optimal efficiency, and the fastest possible processing time, you want to make sure that the CPU is dedicating a maximum percentage of its time to your code processing.
    • Hibernation
    • Suspend Mode
    • Windows Update
    • Anti Virus Software
    • Screen Saver
    • Disk Defragmentation or Optimization Programs
    • Any Resident Applications
  2. Each time this code is executed, Records are dynamically Deleted and Appended to tblSickLeave. Given this cycle, the Database should periodically be Compacted and Repaired.
Aug 21 '08 #49

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
4244
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
3004
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
8676
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
9164
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...
0
9029
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 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...
1
8898
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
8870
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
7734
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...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2006
bsmnconsultancy
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...

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.