473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

How to find total length of service

I am working on an access project for pension calculation. I want to find total length of service between two dates. i.e. if the Date of entry into service is 15/3/1980 and the date of retirement will be 31/1/2010 then the total length of service will be 29 years, 10 months, 17 days.

Kindly help me how to find the length of service in above said format by using VB code in an access project.
Oct 1 '09 #1
2 2565
kadghar
1,295 Expert 1GB
well, you can always use the DATEDIFF function
Oct 2 '09 #2
Private Sub cmdCalculate1_Click()
' create a button like cmdCalculate1
' place a Label in form and name it to lblDifference
'Put two Text Boxes one for txtThen for Retd.date
' and one for txtPens_Calculations for Date of Appointment
' Hi ...I am Deaf & National deaf chess player. I like your comments
' Please test this programme throughly. esakkisivaganesh@yahoo.co.in
Dim dtmAppointt As Date, dtmNow As Date
Dim strYear As String, strMOnth As String, strDay As String
Dim strWeekDay As String, strMessage As String

'set the trap
On Error GoTo BadDate
' convert date the user typed in
dtmAppointt = CDate(txtThen.Text) ' Retirement date
'success!
On Error GoTo 0

'txtPens_Calculations.Text = "01/04/" & Year(Now)

' txtPens_Calculations.Text = Format(Now, "dd/mm/yyyy") 'Year(Now)
dtmNow = txtPens_Calculations.Text 'Date of Entry in Service

'difference in years
strYear = Str$(Year(dtmAppointt) - Year(dtmNow))

'difference in months
strMOnth = Str$(Month(dtmAppointt) - Month(dtmNow))

'differnce in days
strDay = Str$(Day(dtmAppointt) - Day(dtmNow))

'get the day of the week
strWeekDay = Format(dtmAppointt, "dddd") ' strWeekday = to find what day today?
strMessage = strYear & " years, " & strMOnth & " months, " & _
strDay & " days; " & Chr$(10) ' put together the label
strMessage = strMessage & "The day of the week you gave is a " & _
strWeekDay & ","
lblDifference.Caption = strMessage
Exit Sub

BadDate:
errMsgBox "Please type a date in the correct format. i.e. 01/30/2000 MM/DD/Year"
txtThen.SetFocus



End Sub
Oct 24 '09 #3

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

Similar topics

7
by: rick | last post by:
Can anyone help, I am try to create a simple form using a table, where a user can fill out quanty and price and have a total automatically calculated and inserted in another field. I stuck trying...
11
by: mailar | last post by:
Hi, I am using DB2 version 8.2 on Windows XP platform. I have a table 'EMP' with one field named 'NAME' of type CHAR , size 80. Also , I have a record with NAME='john' Now, when I try to...
10
by: Craig Bumpstead | last post by:
Hi, I was wondering the best and fastest way to determine how many lines are in a log file. At the moment I am simply doing a StreamReader.ReadLine and incrementing a counter until I reach...
7
by: felecha | last post by:
I have been developing an app in VB.Net, using a simple form and a button to kick off a class that starts asynchronously receiving from a MessageQueue. It's been working fine, but now I'm moving...
2
by: i33333 | last post by:
codes go here: // ----------------- start --------------------------- var s1 = ; var s2 = ; var s3 = ; var s4 = ; function addNum(arr) {
4
by: Rich_C | last post by:
I'm sure this is very simple, but I have very little experience with javascript -- and what I do know isn't helping me here. I have a simple form where users can enter a quantity (qty) and cost...
2
by: sammiesue | last post by:
Hi, I have form with 2 autosummed textboxes ("total" and "casinototal"). I would like to have a grand total textbox ("grandtotal") get its value from summing "total" and "casinototal", but it...
4
by: drago | last post by:
Hi guys, I will be quick this time... Just want to know how we can calculate generic values in the same column. I am using invoice form with a services subform . I have a column of 'total' in subform...
1
by: Elaine121 | last post by:
Hi i'm writing a program where you have to determine the smallest, number of distinctions and the average from an array of values. in my test class i get an error that says cannot find symbol -...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...
0
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...

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.