jayinthe813
New member
- Local time
 - Yesterday, 18:38
 
- Joined
 - Sep 6, 2012
 
- Messages
 - 6
 
Hello, I am attempting to compare some dates in my queries.  I have created a custom function I am attempting to use in a query.  My function looks like this:
	
	
	
		
the SQL for my query looks like:
	
	
	
		
The field types are the following:
EffectiveDate - Date/Time
DOB - Date/Time
Mode - Number
When I run the query, I am getting Data Type Mismatch in criteria expression.
I think the problem is stemming from my criteria which is:
	
	
	
		
But I am not sure why, as FPDA returns a date type, and dateadd also returns a date type. What is my problem here?
 
		Code:
	
	
	Public Function FPDA(ByVal EffDate As Date, DOB As Date, Mode As Integer, Age As Integer) As Date
'FUNCTION TO CALCULATE THE FIRST PREMIUM DUE AFTER X AGE
Select Case Mode
Case "1"
Do Until EffDate > DateAdd("yyyy", Age, [DOB]) And EffDate >= #4/1/2014# 'alternatively DateAdd("yyyy", 65 (or X age), DOB) if you want to use different age
EffDate = DateAdd("yyyy", 1, EffDate)
Loop
Case "2"
Do Until EffDate > DateAdd("yyyy", Age, [DOB]) And EffDate >= #4/1/2014#
EffDate = DateAdd("m", 6, EffDate)
Loop
Case "4"
Do Until EffDate > DateAdd("yyyy", Age, [DOB]) And EffDate >= #4/1/2014#
EffDate = DateAdd("q", 1, EffDate)
Loop
Case "12"
Do Until EffDate > DateAdd("yyyy", Age, [DOB]) And EffDate >= #4/1/2014#
EffDate = DateAdd("m", 1, EffDate)
Loop
End Select
'return
FPDA = EffDate
End Function
	the SQL for my query looks like:
		Code:
	
	
	SELECT FPDA([EffectiveDate],[DOB],[Mode],60)
FROM tblAccounts INNER JOIN tblMasterData ON tblAccounts.AccountNum = tblMasterData.AccountNum
WHERE (((FPDA([EffectiveDate],[DOB],[Mode],75))<=DateAdd("d",365,Date())));
	The field types are the following:
EffectiveDate - Date/Time
DOB - Date/Time
Mode - Number
When I run the query, I am getting Data Type Mismatch in criteria expression.
I think the problem is stemming from my criteria which is:
		Code:
	
	
	<=DateAdd("d",365,Date())
	But I am not sure why, as FPDA returns a date type, and dateadd also returns a date type. What is my problem here?