Putting total Years in a query

AccessUser1972

New member
Local time
Today, 02:50
Joined
Sep 26, 2013
Messages
6
I have a database of people who have a "Joined" date. i.e. 09/1/2012. I would like to set up a query that tells me how long (in years) that they joined. How might I accomplish this?

Thank you,
Debbie :confused:
 
Create a new field in the query with something like:
Yrs: DateDiff("yyyy",[Joined],Date())
 
I put it in and I get a box that says Parameter. I have never understood the Parameter box.
I click oK , and it comes up with an empty query.
 
For a more accurate calculation, put the code below in a general module:

Code:
 Public Function CalculateAge(DOB As Date) As Integer
    Dim WorkDate As Date
    Dim RawAge As Integer
    RawAge = DateDiff("yyyy", DOB, Date)
    WorkDate = DateSerial(Year(Date), month(DOB), Day(DOB))
    CalculateAge = RawAge + (Date < WorkDate) '(Date < WorkDate) = 0 or -1
End Function
Then use:
Yrs: CalculateAge([YourDateField])
As a field in your query. This should be put in the top line of a blank column.
Replace [YourDateField] with the name of your date field.

I have taken the code above from a db that has been made available by Pat Hartman which I have attached to this post. It has some great functions. I, for one, should like to thank Pat and any other authors involved for making it freely available.
 

Attachments

So CalculateAge([YourDateField]) should be put at the top line called "Field"? I have been putting it down below under "criteria".

Either way, It didn't work. I don't know how to put in the code in a general module. I'm not that advanced in access for that. :)
 
Put:
Yrs:CalculateAge([YourDateField])
in the top line of your query in a blank column. When the query runs "Yrs" will be the name at the top of the column.
To put the function's code in a module, all you need to do is copy the code from my post #4. Open a new module and paste the code.
 

Users who are viewing this thread

Back
Top Bottom