Hi,
I'm pretty sure it's a no brainer for some people, but I'm lost...
I have a form that I use to filter on a report on Access 2000. I use various criterias in list boxes to filter my report and it works for all of them except for the year, where I recieve the message; " Data Type mismatch in criteria expression" I guess it's because my year is extracted from a date (06/06/2007) and the data type is wrong, but I don't know how to solve my issue.
Here's the code:
Private Sub cmdFilter_Click ()
Dim varItem As Variant
Dim strSite_Name As String
Dim strYear As String
Dim strFilter As String
'For Site_Name'
For Each varItem In Me.lstSite_Name .ItemsSelected
strSite_Name = strSite_Name & ",'" & Me.lstSite_Name .ItemData(varIt em) & "'"
Next varItem
If Len(strSite_Nam e) = 0 Then
strSite_Name = "Like '*'"
Else
strSite_Name = Right(strSite_N ame, Len(strSite_Nam e) - 1)
strSite_Name = "IN (" & strSite_Name & ")"
End If
'For Year'
For Each varItem In Me.lstYear.Item sSelected
strYear = strYear & ",'" & Me.lstYear.Item Data(varItem) & "'"
Next varItem
If Len(strYear) = 0 Then
strYear = "Like '*'"
Else:
strYear = Right(strYear, Len(strYear) - 1)
strYear = "IN(" & strYear & ")"
End If
strFilter = "[Site_Name] " & strSite_Name & _
"AND [Year] " & strYear
With Reports![rpt_detail]
.Filter = strFilter
.FilterOn = True
End With
End Sub
Anyone can help?
Thank you
Marie
I'm pretty sure it's a no brainer for some people, but I'm lost...
I have a form that I use to filter on a report on Access 2000. I use various criterias in list boxes to filter my report and it works for all of them except for the year, where I recieve the message; " Data Type mismatch in criteria expression" I guess it's because my year is extracted from a date (06/06/2007) and the data type is wrong, but I don't know how to solve my issue.
Here's the code:
Private Sub cmdFilter_Click ()
Dim varItem As Variant
Dim strSite_Name As String
Dim strYear As String
Dim strFilter As String
'For Site_Name'
For Each varItem In Me.lstSite_Name .ItemsSelected
strSite_Name = strSite_Name & ",'" & Me.lstSite_Name .ItemData(varIt em) & "'"
Next varItem
If Len(strSite_Nam e) = 0 Then
strSite_Name = "Like '*'"
Else
strSite_Name = Right(strSite_N ame, Len(strSite_Nam e) - 1)
strSite_Name = "IN (" & strSite_Name & ")"
End If
'For Year'
For Each varItem In Me.lstYear.Item sSelected
strYear = strYear & ",'" & Me.lstYear.Item Data(varItem) & "'"
Next varItem
If Len(strYear) = 0 Then
strYear = "Like '*'"
Else:
strYear = Right(strYear, Len(strYear) - 1)
strYear = "IN(" & strYear & ")"
End If
strFilter = "[Site_Name] " & strSite_Name & _
"AND [Year] " & strYear
With Reports![rpt_detail]
.Filter = strFilter
.FilterOn = True
End With
End Sub
Anyone can help?
Thank you
Marie
Comment