View Single Post
  #2  
Old June 16th, 2005, 09:56 PM
Marshall Barton
external usenet poster
 
Posts: n/a
Default

Kevin Beck via AccessMonster.com wrote:
I have a report with a form that I am trying to use to filter and then to
sort results.

You choose a "section #" in a combobox named cboSection between 1 and 30 and
then sort the report up to three levels. When I try to apply the filter I get
msg "Data Type Mismatch in Criteria Expression" Does anyone know how to
remedy this? The following code is from the "on click" event of the "filter"
command button.

Private Sub cmdApplyFilter_Click()
Dim strSection As String
Dim strFilter As String
If IsNull(Me.cboSection.Value) Then
strSection = "Like '*'"
Else
strSection = "='" & strSection & "'"
End If

strFilter = "[Section] " & strSection

With Reports![rptCompGranteeLot]
.Filter = strFilter
.FilterOn = True
End With



The line: strSection = "='" & strSection & "'" doesn't
seem to make sense in this procedure. Shouldn't that be
strSection = "='" & Me.cboSection & "'"

Furthermore, if [Section] is a numeric field, then that line
should not include the apostrophes.
strSection = "=" & Me.cboSection

Beyond that issue, you should omit the criteria altogether
when cboSection is Null.

On the other hand, your code is out of context, so I can't
tell what else you have going on. Presumably, there is some
other code that opens the report and that's where I would
expect to specify the report's filter by using the
OpenReport method's WhereCondition argument. I'm not at all
sure that applying the filter property after the report is
opened will even work reliably.

Putting all that together, I would throw that procedure and
its button away and use code more like this in the preview
report button:

stDoc = "rptCompGranteeLot"
If Not IsNull(Me.cboSection)
strWhere = "[Section] =" & Me.cboSection
End If

DoCmd.OpenReport stDoc, , , strWhere

--
Marsh
MVP [MS Access]