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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
"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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Data Type Mismatch problem | SMelissaK | General Discussion | 0 | February 24th, 2005 07:03 PM |
Data type mismatch when passing String sort field to report | F-13 | Setting Up & Running Reports | 1 | January 27th, 2005 03:32 AM |
Data type mismatch in criteria expression. | ian | Running & Setting Up Queries | 2 | December 13th, 2004 05: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 |