Feral
New member
- Local time
- Today, 13:33
- Joined
- Aug 5, 2024
- Messages
- 12
Hello!
I am at my wit's end and need some help understanding on how to fix or improve a Function to implement into a query.
I am trying to find how long an employee has been working at my company but expressed in either Years or Months only. Not both. For example, if an employee has been working for 2 years and 7 months, I want the result to say, "2 years," and if they have worked 0 year and 4 months, I want it to say, "4 months."
Based off of reading other posts trying to find ages using DOB, I attempted to build something similar. I'm very much new to this so please forgive my mistakes. This is why I'm looking for help.
The date we will be referencing is [Hire_Date]. There are no other dates associated with an employee's file.
My understanding of the module is as follows:
From here, I know I'm pretty sure I'm missing an IF statement to have one or the other but I'm not sure how to write that.
When trying to place the Function in a Query Field, it gives me a parameter window and then pulls nothing up, so I know I'm not doing something right with how it is above.
In the Field, it's my understanding it should be, "Tenure: CalcAge([Hire_Date])" correct?
I would appreciate any help and would especially love a breakdown if possible or pointed in the right direction.
Thank you all!
I am at my wit's end and need some help understanding on how to fix or improve a Function to implement into a query.
I am trying to find how long an employee has been working at my company but expressed in either Years or Months only. Not both. For example, if an employee has been working for 2 years and 7 months, I want the result to say, "2 years," and if they have worked 0 year and 4 months, I want it to say, "4 months."
Based off of reading other posts trying to find ages using DOB, I attempted to build something similar. I'm very much new to this so please forgive my mistakes. This is why I'm looking for help.
The date we will be referencing is [Hire_Date]. There are no other dates associated with an employee's file.
My understanding of the module is as follows:
Public Function CalcAge (Hire_Date As Date) As String
Dim intYears As Integer
Dim intMonths As Integer
intYears = intMonths / 12
intMonths = intMonth Mod 12
intMonths = DateDiff("m", [Hire_Date], Date())
If intYears > 0 Then
CalcAge = intYears
If intYears > 1 Then
CalcAge = CalcAge & "years"
Else
CalcAge = CalcAge & "year"
End If
If intMonths > 0 Then
CalcAge = intMonths
If intMonths> 1 Then
CalcAge = CalcAge & "months"
Else
CalcAge = CalcAge & "month"
End If
End Function
From here, I know I'm pretty sure I'm missing an IF statement to have one or the other but I'm not sure how to write that.
When trying to place the Function in a Query Field, it gives me a parameter window and then pulls nothing up, so I know I'm not doing something right with how it is above.
In the Field, it's my understanding it should be, "Tenure: CalcAge([Hire_Date])" correct?
I would appreciate any help and would especially love a breakdown if possible or pointed in the right direction.
Thank you all!
Last edited: