G'day,
I'm struggling with a problem in Access around a SQL query
If I use the following query:
SELECT DET_Data.Country, 0 as R_Status, 0 as X_Status, 0 as A_Status, 1 as C_Status, HP_QTRs.HQTR, HP_QTRs.SMonth, 2012 as RYear, 0 as RMonth, 1 as RQtr
FROM DET_Data, HP_QTRs
WHERE DET_Data.Request_Type="CE"
And (Month([DET_Data.Date_Completed])=HP_QTRs.NMonth)
**AND (HP_FYQ([DET_Data.Date_Completed]) = 20121)**AND ([DET_Data.Win] In ("C"));
I get the error "Data type mismatch in criteria expression"
However if I have the data stored in a field in the db and use the following query:
SELECT DET_Data.Country, 0 as R_Status, 0 as X_Status, 0 as A_Status, 1 as C_Status, HP_QTRs.HQTR, HP_QTRs.SMonth, 2012 as RYear, 0 as RMonth, 1 as RQtr
FROM DET_Data, HP_QTRs
WHERE DET_Data.Request_Type="CE"
And (Month([DET_Data.Date_Completed])=HP_QTRs.NMonth)
**AND ([DET_Data.Date_Completed_FYQ] = 20121)**AND ([DET_Data.Win] In ("C"));
It works as expected
The User defined function is:
Public Function HP_FYQ(ByRef TestDate As Date) As Long
' Pass the queried date
' Returns the financial year
'Debug.Print "testDate is " & testDate
HP_FYQ = ((Year(TestDate) + IIf(Month(TestDate) > 10, 1, 0)) * 10) + (Int((((Month(TestDate) + 1) Mod 12) / 3) + 1))
End If
End Function
I have set up a test form and the function returns the expected value
Everything works with internal functions, like "month" as used above, but it seems like using a UDF is a problem for some reason, or more likely the way I have done it.
Advise appreciated.
Thanks