BillieBurgess
Technical User
I have Access 2002
Last Year Paul Bricker helped me create a Function that listed the Fiscal Month. Our Month-end is the last Friday of the Month. I then wrote a code that listed the Fiscal Year (Oct - Sept). The Function works great in reports but not so great in Queries. Whenever I try to use it as a criteria I get this Error "Data Type Mismatch in Criteria Expression" and then all the fields in the query go bad (#Name?). I have tried enclosing the criteria in quotations for text data, number signs for date data, percent signs for variant data (desperate), but nothing seems to work. Both Modules are below, but I suspect the problem is the same for both. If someone could either help me better define the data type, find a way to query for them or help me fix whatever I have wrong I would sincerely appreciate it.
Function Fiscal_Month(dteInput As Date) 'Returns the last Friday of month for printing report.
Dim intDays As Integer
Dim x As Date
Dim MyDate As Date
intDays = DateSerial(Year(dteInput), Month(dteInput) + 1, Day(dteInput)) _
- DateSerial(Year(dteInput), Month(dteInput), Day(dteInput))
x = DatePart("m", dteInput) & "/" & intDays & "/" & DatePart("yyyy", dteInput)
Select Case Weekday(x)
Case 1
MyDate = x - 2
Case 2
MyDate = x - 3
Case 3
MyDate = x - 4
Case 4
MyDate = x - 5
Case 5
MyDate = x - 6
Case 7
MyDate = x - 1
Case Else
MyDate = x
End Select
If dteInput > MyDate Then
Fiscal_Month = Month(dteInput) + 1
If Fiscal_Month = 13 Then
Fiscal_Month = 1
End If
Else
Fiscal_Month = Month(dteInput)
End If
End Function
Function Fiscal_Year(dteInput As Date) 'Returns the last Friday of month for printing report.
Dim intDays As Integer
Dim intYear As Variant
Dim x As Date
Dim MyDate As Date
intDays1 = DateSerial(Year(dteInput), Month(dteInput) + 1, Day(dteInput)) _
- DateSerial(Year(dteInput), Month(dteInput), Day(dteInput))
x = DatePart("m", dteInput) & "/" & intDays1 & "/" & DatePart("yyyy", dteInput)
Select Case Weekday(x)
Case 1
MyDate = x - 2
Case 2
MyDate = x - 3
Case 3
MyDate = x - 4
Case 4
MyDate = x - 5
Case 5
MyDate = x - 6
Case 7
MyDate = x - 1
Case Else
MyDate = x
End Select
If dteInput > MyDate Then
Int_Days = Month(dteInput) + 1
Else
Int_Days = Month(dteInput)
End If
If Int_Days > 9 Then
Fiscal_Year = Year(dteInput) + 1
Else
Fiscal_Year = Year(dteInput)
End If
Exit Function
End Function
Last Year Paul Bricker helped me create a Function that listed the Fiscal Month. Our Month-end is the last Friday of the Month. I then wrote a code that listed the Fiscal Year (Oct - Sept). The Function works great in reports but not so great in Queries. Whenever I try to use it as a criteria I get this Error "Data Type Mismatch in Criteria Expression" and then all the fields in the query go bad (#Name?). I have tried enclosing the criteria in quotations for text data, number signs for date data, percent signs for variant data (desperate), but nothing seems to work. Both Modules are below, but I suspect the problem is the same for both. If someone could either help me better define the data type, find a way to query for them or help me fix whatever I have wrong I would sincerely appreciate it.
Function Fiscal_Month(dteInput As Date) 'Returns the last Friday of month for printing report.
Dim intDays As Integer
Dim x As Date
Dim MyDate As Date
intDays = DateSerial(Year(dteInput), Month(dteInput) + 1, Day(dteInput)) _
- DateSerial(Year(dteInput), Month(dteInput), Day(dteInput))
x = DatePart("m", dteInput) & "/" & intDays & "/" & DatePart("yyyy", dteInput)
Select Case Weekday(x)
Case 1
MyDate = x - 2
Case 2
MyDate = x - 3
Case 3
MyDate = x - 4
Case 4
MyDate = x - 5
Case 5
MyDate = x - 6
Case 7
MyDate = x - 1
Case Else
MyDate = x
End Select
If dteInput > MyDate Then
Fiscal_Month = Month(dteInput) + 1
If Fiscal_Month = 13 Then
Fiscal_Month = 1
End If
Else
Fiscal_Month = Month(dteInput)
End If
End Function
Function Fiscal_Year(dteInput As Date) 'Returns the last Friday of month for printing report.
Dim intDays As Integer
Dim intYear As Variant
Dim x As Date
Dim MyDate As Date
intDays1 = DateSerial(Year(dteInput), Month(dteInput) + 1, Day(dteInput)) _
- DateSerial(Year(dteInput), Month(dteInput), Day(dteInput))
x = DatePart("m", dteInput) & "/" & intDays1 & "/" & DatePart("yyyy", dteInput)
Select Case Weekday(x)
Case 1
MyDate = x - 2
Case 2
MyDate = x - 3
Case 3
MyDate = x - 4
Case 4
MyDate = x - 5
Case 5
MyDate = x - 6
Case 7
MyDate = x - 1
Case Else
MyDate = x
End Select
If dteInput > MyDate Then
Int_Days = Month(dteInput) + 1
Else
Int_Days = Month(dteInput)
End If
If Int_Days > 9 Then
Fiscal_Year = Year(dteInput) + 1
Else
Fiscal_Year = Year(dteInput)
End If
Exit Function
End Function