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: - Public Sub cmdTest_Click()
-
On Error GoTo Err_cmdTest_Click
-
Dim strSQL As String
-
Dim MyDB As DAO.Database
-
Dim rstUniqueEmployees As DAO.Recordset
-
Dim rstFinalResults As DAO.Recordset
-
Dim rstIntervals As DAO.Recordset
-
Dim bytHolidaysInInterval As Byte
-
Dim varTotalSickHours As Variant
-
Dim strInterval As String
-
Dim lngStartTime As Long
-
Dim lngEndTime As Long
-
-
DoCmd.Hourglass True 'visual indicator of processing
-
lngStartTime = timeGetTime() 'Start the Timer
-
-
'Generate Unique Employee IDs in Ascending Order
-
strSQL = "SELECT DISTINCT [LEAVE 2007-2008].PERNR FROM " & _
-
"[LEAVE 2007-2008]ORDER BY [LEAVE 2007-2008].PERNR;"
-
-
'Delete all entries in the previous tblSickLeave Output Table
-
CurrentDb.Execute "Delete * From tblSickLeave", dbFailOnError
-
-
Set MyDB = CurrentDb() 'refers to the Current Database
-
Set rstUniqueEmployees = MyDB.OpenRecordset(strSQL, dbOpenSnapshot)
-
Set rstIntervals = MyDB.OpenRecordset("Select * From tbl2WeekIntervals;", dbOpenSnapshot)
-
Set rstFinalResults = MyDB.OpenRecordset("tblSickLeave", dbOpenDynaset)
-
-
'Cross reference every Employee ([PERNR]) against every 2 week Interval ([Start_Date]/[End_Date]),
-
'at this intersection check the value of the [Holiday] Field (0, 1, 2, or 3), to see
-
'if a Holiday/Holidays occurred for the specified Interval, calculate the Total Hours [CATSHOURS]
-
'for each Employee/Interval. Check and see if this figure is at least 75 Hours for a No-Holiday-Interval,
-
'or 67.5 Hours for a single Holiday Interval, 60 Hours for a 2-Holiday Interval, or 52.5 Hours for a
-
'a 3-Holiday Interval.
-
With rstUniqueEmployees 'Employees
-
Do While Not .EOF
-
Do While Not rstIntervals.EOF '2-Week Intervals
-
'bytHolidaysInInterval = DLookup("[Holidays]", "tbl2WeekIntervals", "[Start_Date] = #" & _
-
'rstIntervals![Start_Date] & "# And [End_Date] = #" & _
-
'rstIntervals![End_Date] & "#") '0,1,2, or 3 Holiday(s) in Interval?
-
bytHolidaysInInterval = rstIntervals![Holidays]
-
'Total Sick Hours for the Employee for the specified 2-Week Interval
-
varTotalSickHours = DSum("[CATSHOURS]", "LEAVE 2007-2008", "[WorkDate] Between #" & _
-
rstIntervals![Start_Date] & "# And #" & rstIntervals![End_Date] & _
-
"# And [PERNR] = " & ![PERNR])
-
If bytHolidaysInInterval = 0 Then 'NO Holiday in Interval
-
If varTotalSickHours >= 75 Then 'minimum of 75 hrs. for NO Holiday
-
strInterval = strInterval & "+" 'qualifies
-
Else
-
strInterval = strInterval & "-" 'non-qualifier
-
End If
-
ElseIf bytHolidaysInInterval = 1 Then '1 Holidays in Interval
-
If varTotalSickHours >= 67.5 Then 'minimum of 67.5 hrs. for 1 Holiday
-
strInterval = strInterval & "+" 'qualifies
-
Else
-
strInterval = strInterval & "-" 'non-qualifier
-
End If
-
ElseIf bytHolidaysInInterval = 2 Then '2 Holidays in Interval
-
If varTotalSickHours >= 60 Then 'minimum of 60 hrs. for 2 Holidays
-
strInterval = strInterval & "+" 'qualifies
-
Else
-
strInterval = strInterval & "-" 'non-qualifier
-
End If
-
ElseIf bytHolidaysInInterval = 3 Then '3 Holidays in Interval
-
If varTotalSickHours >= 52.5 Then 'minimum of 52.5 hrs. for 3 Holidays
-
strInterval = strInterval & "+" 'qualifies
-
Else
-
strInterval = strInterval & "-" 'non-qualifier
-
End If
-
End If
-
rstIntervals.MoveNext 'Next Interval for Employee
-
Loop
-
rstFinalResults.AddNew
-
rstFinalResults![Employee] = ![PERNR] 'Add Employee ID
-
rstFinalResults![IntervalString] = strInterval 'Add concatenated Pattern String
-
rstFinalResults.Update
-
-
strInterval = "" 'Reset for next Employee
-
rstIntervals.MoveFirst 'Move to the next 2-Week Interval
-
.MoveNext 'Move to the next Employee
-
Loop
-
End With
-
-
rstIntervals.Close
-
rstUniqueEmployees.Close
-
rstFinalResults.Close
-
Set rstUniqueEmployees = Nothing
-
Set rstIntervals = Nothing
-
Set rstFinalResults = Nothing
-
-
Me![cmdFinalize].Enabled = True
-
-
lngEndTime = timeGetTime() 'End Timer (end of the line!)
-
-
Debug.Print "************ Process 1 Execution Time ************"
-
Debug.Print "Test PC: Pentium(R) M - 1.60 GHz - 512 MB RAM"
-
Debug.Print "Seconds: " & FormatNumber((lngEndTime - lngStartTime) / 1000, 2)
-
Debug.Print "Minutes: " & FormatNumber(((lngEndTime - lngStartTime) / 1000) / 60, 2)
-
Debug.Print "Hours : " & FormatNumber((((lngEndTime - lngStartTime) / 1000) / 60) / 60, 4)
-
Debug.Print "**************************************************"
-
-
DoCmd.Hourglass False 'indicates end of processing
-
-
Exit_cmdTest_Click:
-
Exit Sub
-
-
Err_cmdTest_Click:
-
DoCmd.Hourglass False
-
MsgBox Err.Description, vbExclamation, "Error in cmdTest_Click()"
-
Resume Exit_cmdTest_Click
-
End Sub
-
Timing Results: -
Process Seconds Minutes Hours Records
-
1 781.3 12.84 0.217 5000
-
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.
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: - The Data set you gave me consists of 100,017 Records in the Leave 2007-2008 Table.
- Within these Records are 5,359 Employees with accumulated data.
- 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.
- 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.
- At each juncture of Employee <==> 2-Week Interval, the following must be done:
- The number of Holidays within that Interval has to be determined, that info is already contained within the Recordset, so no problem there.
- The Total Sick Hours for each Employee per Interval has to calculated.
- This summation has to be compared to certain constant values depending on the Holidays occurring in that Interval.
- The Pattern String has to be appended to with either a '-' or "*" depending on the previous outcome.
- This is really an enormous, and very time consuming, undertaking.
- 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.
- 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?
- 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.
- 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.
- For all practical purposes, once this has been accomplished, this Thread will effectively be closed.
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: - ************ Process 1 Execution Time ************
-
Records: 100,017
-
Test PC: Pentium(R) M - 1.60 GHz - 512 MB RAM
-
Seconds: 253,358.56
-
Minutes: 4,222.64
-
Hours : 70.3774
-
Days: 2.93
-
**************************************************
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.
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
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
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.
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.
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)
ADezii 8,834
Recognized Expert Expert Two closing points, Erik, and two I feel that are worth mentioning:- 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
- 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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.
|
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...
|
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.
|
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
------------------------------
|
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?
| |
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...
|
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...
|
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;
|
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...
|
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...
|
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: 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...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |