Query with sql, function and input parameter

S

Stephanie

Over my head! I need to modify a query by adding a column that needs to be
calculated in a function. But I can't quite get it right.

Here's the pertinent snip of the query:
SELECT Contacts.MemberDate, Diff2Dates("ymd",[MemberDate],[ReferenceDate:
(MM/DD/YY)],True) AS [Length of Service],
Diff2Dates("my",[MemberDate],[ReferenceDate: (MM/DD/YY)],True) AS [Years of
Service],
AgeF("MemberDate","ReferenceDate") AS Years

Here's the function:
Public Function AgeF(MemberDate, ReferenceDate) As Integer
' Returns the Age in years between 2 dates
' Doesn't handle negative date ranges i.e. Bdate > DateToday

If Month(ReferenceDate) < Month(MemberDate) Or (Month(ReferenceDate) =
Month(MemberDate) And Day(ReferenceDate) < Day(MemberDate)) Then
Age = Year(ReferenceDate) - Year(MemberDate) - 1
Else
Age = Year(ReferenceDate) - Year(MemberDate)
End If
End Function

I want the user to enter the reference date (as it will change).
One of the MVPs indicated that calculations from the sql won't allow me to
sort the years correctly (11, 10 and 1 get grouped together). So I believe
the function will take the place of the sql years of service. But I can't
figure out how to get the function to calculate the years for me so I can
have a Year header in a report and then group the pertinent length of
services under the header in a report.

When I run the query, I get a run-time error 13: type mismatch before I even
get to enter the reference date.

I'd appreciate your insight. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top