Solved

Automatic Calculation

Posted on 2002-05-21
4
198 Views
Last Modified: 2010-05-02
I'm developing a product for my HR department that will calculate vacation time and such based on date of hire all beginning after 6 months and will vary on the length of time the employee has been here.

I'm having problems figuring out some of the logic.  Say I enter a employee who's hire date is today which would be less than six months.  An entry would be created in the database for vacation used as 0.

Now, the problem comes in how I check each employees record every day and when it comes time for their 6 month or 2 year anniversary to update the record with the appropriate amount of time.

Any help on this logic would be greatly appreciated.  
0
Comment
Question by:baddogi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 2

Expert Comment

by:Crin
ID: 7025356
Hello,

Actually it is better to store hiring date and then perform simple calculations.

DayOf6Month = DateSerial(Year(HireDate), Month(HireDate) + 6, Day(HireDate))

Sincerely,
Crin
0
 
LVL 2

Accepted Solution

by:
Crin earned 200 total points
ID: 7025384
Of course then you will be able to find how many days, months or years one or another employee is here.

DaysCount = Now - HireDate
MonthsCount = (Year(Now) - Year(HireDate)) * 12 + _
        (Month(Now) - Month(HireDate))
 
Additional advantage of this approach is that software should not perform operations every day (just suppose computer will be off one day and every employee will lose one day of the employment history).

Sincerely,
Crin
0
 

Author Comment

by:baddogi
ID: 7025399
Thanks, I'll give that a try.....
0
 
LVL 2

Expert Comment

by:Crin
ID: 7025424
Ouch, forgot to send YearsCount formula:

Dim YearsCount as Double
YearsCount = DaysCount / 365.25

which will adequatelly take care about leap-years.

Also, for more precise MonthsCount formula you can get this one (previous calculated integer months):

Dim FirstMonthPart as Double
Dim LastMonthPart as Double
Dim MonthsCount as Double

FirstMonthPart = (DateSerial(Year(HireDate), Month(HireDate) + 1, 0) - HireDate) / _
     (DateSerial(Year(HireDate), Month(HireDate) + 1, 0) - DateSerial(Year(HireDate), Month(HireDate), 1))

LastMonthPart = (Now - DateSerial(Year(Now), Month(Now), 1) - Now) / _
     (DateSerial(Year(Now), Month(Now) + 1, 0) - DateSerial(Year(Now), Month(Now), 1))

MonthsCount = (Year(Now) - Year(HireDate)) * 12 + _
       (Month(Now) - Month(HireDate)) + _
       FirstMonthPart + LastMonthPart


Sincerely,
Crin
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question