G
Guest
I'm using Access XP.
I am trying to produce a query that lists students in our database who are
first or second year students in our program. To that end I have produced a
function that returns an integer indicating what year of the program a
student is in.
The function is simple and seems to be working properly from the immediate
window:
Public Function GetStudentYear(ByVal GradYearString As String) As Integer
GetStudentYear = (GetAcademicYear() - CInt(GradYearString)) + 2
End Function
Yes, the database stores their expected year of graduation rather than when
they came in, and as a string rather than a number. I did not design the
database and I'm not allowed to change it; I'm just trying to work with it.
As I said, this function seems to be producing good data. I can include it
in the query without problem, except when I attempt to add criteria. If I
make a field:
Student Year: GetStudentYear([AGradDate])
And put a number in for a criteria, the computer throws a "Data type
mismatch in criteria expression. (Error 3464)" at me. I do not see any
reasonable cause for this. I have stepped through the routine and the error
doesn't occur during the operation of the VBA code, but after the function
exits. There is nothing unusual about the point where the error occurs, it
is the same string value "2006" that is returned as a integer 2 as many were
before.
Can anyone give me any idea where to look for a problem?
I am trying to produce a query that lists students in our database who are
first or second year students in our program. To that end I have produced a
function that returns an integer indicating what year of the program a
student is in.
The function is simple and seems to be working properly from the immediate
window:
Public Function GetStudentYear(ByVal GradYearString As String) As Integer
GetStudentYear = (GetAcademicYear() - CInt(GradYearString)) + 2
End Function
Yes, the database stores their expected year of graduation rather than when
they came in, and as a string rather than a number. I did not design the
database and I'm not allowed to change it; I'm just trying to work with it.
As I said, this function seems to be producing good data. I can include it
in the query without problem, except when I attempt to add criteria. If I
make a field:
Student Year: GetStudentYear([AGradDate])
And put a number in for a criteria, the computer throws a "Data type
mismatch in criteria expression. (Error 3464)" at me. I do not see any
reasonable cause for this. I have stepped through the routine and the error
doesn't occur during the operation of the VBA code, but after the function
exits. There is nothing unusual about the point where the error occurs, it
is the same string value "2006" that is returned as a integer 2 as many were
before.
Can anyone give me any idea where to look for a problem?