Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 20th, 2004, 08:23 AM
Authorized User
 
Join Date: Dec 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Default need help for function

Hi..
In my table Name,DOB(Date of Birth),DOA(Date of appointment) field are there
now I want DOR(Date of Retirement) after 60 yers if DOB is 1st day of month
DOR should come last day of previews month otherwise last day of month after
60 years and I wnat qualifing service like No of days, No of Month & No of
years from DOA field-DOR field. so please how should write function in MS.Access

Mohamed Mohiddin
Officer
__________________
Mohamed Mohiddin
Officer
 
Old July 20th, 2004, 12:18 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Hi Mohamed,

This should get your date of retirement. Just use the DateDiff function to calculate your total days, months, years:

Sub RetirmentDate(datDateOfBirth As Date)

    Dim datRetirementFlag As Date
    Dim datDateOfRetirement As Date

    datRetirementFlag = DateAdd("yyyy", 60, datDateOfBirth)

    If (datDateOfBirth = FirstDayofMonth(datDateOfBirth)) Then
        datDateOfRetirement = LastDayofPreviousMonth(datRetirementFlag)
    Else
        datDateOfRetirement = LastDayofMonth(datRetirementFlag)
    End If

    Debug.Print datDateOfRetirement

End Sub

Function FirstDayofMonth(datDOB As Date)
    FirstDayofMonth = DateAdd("d", 1 - DatePart("d", datDOB), datDOB)
End Function

Function LastDayofPreviousMonth(datRF As Date)
  LastDayofPreviousMonth = (DateAdd("d", 1 - DatePart("d", datRF), datRF)) - 1
End Function

Function LastDayofMonth(datRF As Date)
  LastDayofMonth = DateSerial(DatePart("yyyy", datRF), DatePart("m", datRF) + 1, 1) - 1
End Function

HTH,

Bob

 
Old June 8th, 2005, 01:47 PM
Registered User
 
Join Date: Jun 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here's an alternate way of calculating the beginning and ending days of the month for use with the above solution.

Public Function BegOfMonth(DateIn As Date) As Date
BegOfMonth = DateAdd("d", -(Day(DateIn) - 1), DateIn)
End Function

Public Function EndofMonth(DateIn As Date) As Date
EndofMonth = DateAdd("d", -1, (DateAdd("m", 1, BegOfMonth(DateIn))))
End Function

[email protected]






Similar Threads
Thread Thread Starter Forum Replies Last Post
function keyvanjan ASP.NET 2.0 Professional 1 September 19th, 2007 10:22 AM
How to use Function akumarp2p SQL Server 2000 1 May 28th, 2007 05:04 AM
send variable in function to another function schoolBoy Javascript How-To 6 March 3rd, 2007 09:16 AM
How to call javascript function from VB function vinod_yadav1919 VB How-To 0 February 13th, 2006 06:03 AM
retreive function/Line from macro or function? MikoMax J2EE 0 April 1st, 2004 04:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.