A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Setting Up & Running Reports
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

"data type mismatch" trying to execute dialogue form



 
 
Thread Tools Display Modes
  #1  
Old June 16th, 2005, 03:55 PM
Kevin Beck via AccessMonster.com
external usenet poster
 
Posts: n/a
Default "data type mismatch" trying to execute dialogue form

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

--
Message posted via http://www.accessmonster.com
  #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]
  #3  
Old June 17th, 2005, 03:53 AM
Kevin Beck via AccessMonster.com
external usenet poster
 
Posts: n/a
Default

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

--
Message posted via http://www.accessmonster.com
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Type Mismatch problem SMelissaK General Discussion 0 February 24th, 2005 08:03 PM
Data type mismatch when passing String sort field to report F-13 Setting Up & Running Reports 1 January 27th, 2005 04:32 AM
Data type mismatch in criteria expression. ian Running & Setting Up Queries 2 December 13th, 2004 06:45 PM
Data type mismatch in criteria expression Tcs Running & Setting Up Queries 2 October 8th, 2004 08:05 PM
SQL view of messed up action queries Kendra Running & Setting Up Queries 2 August 31st, 2004 09:53 PM


All times are GMT +1. The time now is 08:20 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.