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