"data type mismatch" trying to execute dialogue form

  • Thread starter Kevin Beck via AccessMonster.com
  • Start date
K

Kevin Beck via AccessMonster.com

Hey,

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
End Sub

Many thanks for anyone who might be able to help

Kawg
 
M

Marshall Barton

Kevin said:
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
 
K

Kevin Beck via AccessMonster.com

M Barton,

The actual issue was treating the numeric field as a text field, which is
what gave me the error.

so:
"[Section]=" & me.cboSection.Value

is what I ended up with.

Also, thanks for the code. I didn't know there was a If Not IsNull was an
arguement (new at vba!), which cleans up my code considerably. Many thanks
for your help

Kawg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top