473,804 Members | 4,217 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adjusting Dates with cap

tuxalot
200 New Member
I have a table (TblDateHistory ) to record lost days due to injuries:

Expand|Select|Wrap|Line Numbers
  1. EmployeeID    StartDate  ReturnDate  RestrictedOrLostDays       TotalDays
  2.  
  3.      1          ...          ...     Lost Time Days                36
  4.      1          ...          ...     Restricted / Transfer Days    50
  5.      2          ...          ...     Lost Time Days                10
  6.      3          ...          ...     Restricted / Transfer Days     8
  7.      1          ...          ...     Lost Time Days                36
  8.      3          ...          ...     Lost Time Days                 3
  9.      3          ...          ...     Restricted / Transfer Days    14
  10.      2          ...          ...     Lost Time Days                 6
  11.      1          ...          ...     Lost Time Days                60
Assume the dates above are sorted ascending.

I have two textboxes txtLostTime and txtRestrictedWo rk bound to
TblEmployeeInju ry.AwayFromWork and TblEmployeeInju ry.JobTransferO rRestiction
which keep running totals of each lost time day, so this bit works.

The function that updates the textboxes is as follows:

Expand|Select|Wrap|Line Numbers
  1. Public Function fSumDaysOff(strLostdays As String) As Long
  2. 'Feed in to variable strLostdays either "Lost Time Days" or
  3. '"Restricted / Transfer Days" where apropriate
  4. 'http://www.oreilly.com/pub/h/3323
  5. 'Chr(34) = "
  6.  
  7. Dim strSQL As String
  8. Dim strSQL1 As String
  9. Dim strSQL2 As String
  10. Dim strSQL3 As String
  11. Dim strSQL4 As String
  12. Dim strSQL5 As String
  13. Dim strSQL6 As String
  14.  
  15. strSQL1 = "SELECT Sum([ReturnDate]-[StartDate]) AS SumDaysOff "
  16. strSQL2 = "FROM [TblDateHistory] "
  17. strSQL3 = "GROUP BY [RestrictedOrLostDays], [EmployeeID] "
  18. strSQL4 = "HAVING ((([RestrictedOrLostDays])="
  19.     'strLostdays
  20. strSQL5 = ") AND (([EmployeeID])="
  21.     'EmployeeID
  22. strSQL6 = "))"
  23.  
  24.   strSQL = strSQL1 & strSQL2 & strSQL3 & strSQL4 & Chr(34) & strLostdays _
  25.   & Chr(34) & strSQL5 & Forms!FrmMain!.EmployeeID & strSQL6
  26.  
  27.   Dim conn As ADODB.Connection
  28.   Set conn = CurrentProject.Connection
  29.   Dim rs As New ADODB.Recordset
  30.   rs.Open strSQL, conn, adOpenKeyset, adLockOptimistic
  31.   'MsgBox rs.Fields("SumDaysOff")
  32.   fSumDaysOff = rs.Fields("SumDaysOff")
  33.   rs.Close
  34.   Set rs = Nothing
  35.   Set conn = Nothing
  36.  
  37. If IsNull(EmployeeID) Then Exit Function
  38.  
  39. End Function      'fSumDaysOff
  40.  
What needs to happen:

Assume for the sake of brevity:
A = Lost Time Days
B = Restricted / Transfer Days

If and when the sum of A+B reaches 180, stop counting.

Here's the tricky part. Example: If the current Sum A+B=179 and an entry of B is recorded with a value of 6, I need to add 1 to the Sum A+B to reach 180, and record the remaining 5 in a "Remainder" field in the table. Why you ask? Because the user can go back and make corrections to A & B row entries, and if a table row is deleted or changed I need to add the remainder back to the sum(A+B).

Example using the data above:

EmployeeID 1:

A=132
B=50

Sum=182. We have reached our cap of 180, so the two text boxes on my form would read:

txtLostTime.Val ue = 130
txtRestrictedWo rk.Value = 50

2 Total Days from the last table row above would be placed in a "remainder" column (i.e. from the total of 60, 58 were added to reach 180 leaving an 'A' remainder of 2).

Now a user goes back and makes some changes. Say they change row 2 in the table at the top to Restricted / Transfer Days=45 from the original total of 50.

Now the two text boxes would read:

txtLostTime.Val ue = 132
(130 original A total) plus 2 (bring remainder back into sum)

and

txtRestrictedWo rk.Value = 45 (50 original B total) minus 5 (reduction in row 2).

Earlier dates take precedence, so if remainder days are added back into the sum earlier remainder dates should be taken first.

I tried to explain this as clear as I can and I hope it makes sense. It is real complicated to me, being new to Access but hopefully someone has a solution.

Thanks very much for taking a look.
Mar 13 '09 #1
10 1466
NeoPa
32,579 Recognized Expert Moderator MVP
You may find someone who is willing to take you further along this path.

I will limit myself at this time to linking you to an article (Normalisation and Table structures) which explains why this approach (updating and storing calculated values) is such a bad idea and is likely to leave you with complicated problems such as this one.
Mar 13 '09 #2
ADezii
8,834 Recognized Expert Expert
I agree with NeoPa in that this problem is a lot more complicated than initially envisioned, especially since your data is not in a 'Normalized' State. If, for whatever reason, you wish to keep your data and structure in its current State, I would request that you display some sample Test Data, say 12 Records for a specific individual. You have previously defined your Table Name, along with the Fields that comprise it. Just some realistic data, and what the outcome from this data should be, will do the trick.
Mar 13 '09 #3
tuxalot
200 New Member
Hi All, thanks for the response. For my project, the database consists of 17 tables and the one mentioned in this post is the only one arranged like this. I read the post about Normalizing and it was very informative so thanks for that. I would be interested in tips on how I can store this data using a different structure. Based on your comments, it seems that this change would make a calculation such as is mentioned here a bit easier.

I only have sample data in this database, so I will create some more entries and attach the db to a post in this thread this weekend for your review.

Thanks again for your help.
Mar 14 '09 #4
ADezii
8,834 Recognized Expert Expert
@tuxalot
You are quite welcome, I'l be checking in again during the weekend. Itm is probably a good idea to provide the specifics of your Employee Table, such as: Table Name, Field Names, Field Data Types, Validation Rules, etc.
Mar 14 '09 #5
tuxalot
200 New Member
Thanks. Here's something to chew on while I prepare a response to your previous post. This is what I need to do in a nutshell.

if sum(A+B)<180, determine if there are any remainder days to be had. If not, do nothing. If so, look at remainder column for the active EmployeeID and beginning with the oldest date, add remainder days (A or B, doesn't matter) back into the Sum(A+B) up to a total of 180. If we reach 180 then revert back to placing remainder data back into A & B remainder columns for all loss days going forward.

Thanks ADezii for offering HOPE.

Tux
Mar 14 '09 #6
ADezii
8,834 Recognized Expert Expert
@tuxalot
tuxalot, this will probably be a long, drawn-out process, involving restructuring and figuring out an Algorithm that will efficiently accomplish what you are requesting (no clue what that is at this point). I'll do the best I can to help you with this Project, but I cannot guarantee anything beyond that. If all this is acceptable, and if there are no time constraints, then we can move on.
Mar 14 '09 #7
tuxalot
200 New Member
Sounds like a plan. Where shall we begin?
Mar 14 '09 #8
ADezii
8,834 Recognized Expert Expert
@tuxalot
  1. Sample data (Test Records) from tblDateHistory.
  2. Name of your Employees Table along with all the Field Names and their Data Types which comprise the Employees Table.
  3. Sample data from the Employees Table representing 3 Employees (don't have to be real, can be fictitious). This data should match corresponding Records in tblDateHistory.
Mar 14 '09 #9
tuxalot
200 New Member
Hi ADezii,

I've re-thought how to go about this, and I think I am going to do this at report time as this is really when the cap days at 180 is required for OSHA recordkeeping purposes. Let's close the thread on this for the time being. I may be able to bang together a query to get this done at report time.

Thanks. Sorry if I burned up a few brain cells :)
Mar 15 '09 #10

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

Similar topics

4
1895
by: Ken Fine | last post by:
No joy on Macromedia's boards after a few days; maybe someone can help me here. I got an excellent string handling function off of planet-source-code.com that converts text strings to proper case, i.e. "the REMAINS of the DAY" is converted to "The Remains Of The Day". This function is particularly good in that it handles certain exceptions. Can you help me make it handle more? I'm interested in two tweaks, one easy, one hard.
10
3298
by: Colin Steadman | last post by:
I'm a stupid ASP programmer and I dont do Javascript (except for very simple tasks anyway), and I'm in a bit of a predicament. I've used a javascript table sorting script from here: http://www.ipwebdesign.net/kaelisSpace/useful_tableSort.html This works great except it doesn't sort my UK formatted dates properly, and I end up with something like this: Birth Date (dd/mm/yyyy)
7
3207
by: Jim Davis | last post by:
I'm (still) working on an ISO 8601 date parser. I want to convert at least the formats described here: http://www.w3.org/TR/NOTE-datetime Well.. I've got most of it working (via RegEx's) good enough for me but I'm having a brain block when it comes to TimeZone. The datetime may come with an optional timezone offset (from GMT) as here (the offset is +1 hour from GMT):
7
10851
by: marfi95 | last post by:
I'm trying to implement some code in vb.net to allow the user to adjust the brightness or contrast on an image (through the use of a slider) that is already black & white in the bitmap. I have tried to use the colormatrix and even down to the pixel using GetPixel and SetPixel in system.drawing, but I'm really not up on using gdi+ and haven't really gotten anywhere. I've seen some examples for VB6, but I need vb.net. I know that all...
1
1508
by: Mark | last post by:
Hi All, I have set up a simple database to create labels for bottles. I insert a set number of records into a table and have produced a label report based on that table. After a bit of tweaking, the labels fit perfectly to the A4 label sheets I have. The problem I have is that I want to the report to be dynamic. If I purchase a different style of label, I need to go into the design of the report to modify widths, heights, column counts,...
12
2448
by: Dixie | last post by:
I am trying to calculate the number of workdays between two dates with regards to holidays as well. I have used Arvin Meyer's code on the Access Web, but as I am in Australia and my date format is dd/mm/yyyy, I have found that the dates I put in my holidays table are reversed into American dates. So, the wrong holiday dates are subtracted from the total workdays between the start and end dates. Is there an easy fix for this? ******Code...
1
15799
by: pitfour.ferguson | last post by:
My dbase has the start date and end date of each visit. How can I ask Access to list the day of the week of the start (easy), end (easy) and, more importantly, the dates of the visit itself - ie list the dates between the start and end date. Basically I am doing a day of the week analysis and need to know which day of the week is busiest.
2
2113
by: pramodh | last post by:
adjusting the baseline of an external text to import in flash
3
3898
by: bmahussain | last post by:
Anybody having javascript coding for adjusting brightness and contrast of an image using slider control. If yes, then kindly forward the same. regards, hussain.
0
9707
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
9585
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,...
0
10586
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
10338
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...
0
9161
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
7622
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
5658
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2997
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.