Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data type mismatch in criteria expression 1

Status
Not open for further replies.

TBOB

Technical User
Jun 22, 2002
65
US
I'm trying to build an SQL string via a criteria form that finds a record. I build the string using the following code located in the code module for the form:

Function BuildSQLString(strSQL As String) As Boolean

Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String

strSELECT = "DEMARC.*"

strFROM = "DEMARC"

strWHERE = "ifrf = " & cboFRAME & " and ifrb = " & cboBLOCK & " and ifrr = " & cboROW & " and ifrp = " & cboPAIR

strSQL = "SELECT " & strSELECT
strSQL = strSQL & "FROM " & strFROM
strSQL = strSQL & " WHERE " & strWHERE

BuildSQLString = True

End Function

Private Sub cmdQUERY_Click()

Dim strSQL As String

'If Not ENTRIESVALID Then Exit Sub

If Not BuildSQLString(strSQL) Then
MsgBox "PROBLEM"
Exit Sub
End If

MsgBox strSQL

CurrentDb.QueryDefs("qryDEMARC").SQL = strSQL

End Sub

The string looks good and when I look at the qryDEMARC in the design window. The SQL View of the design query it looks like the following:

SELECT DEMARC.*
FROM DEMARC
WHERE (((DEMARC.ifrf)="7") AND ((DEMARC.ifrb)="1") AND ((DEMARC.ifrr)="1") AND ((DEMARC.ifrp)="19"));

The problem is when I try to run it I get a msgbox stating "Data type mismatch in criteria expression". I created a seperate query that looks just like the above and it works fine. The other strange thing is if I change anything in the design window, such as toggle the show on one of the fields and then run it, it works. Any help will be greatly appreciated.

Thanks,

Tony




 
If any of ifrf, ifrb, ifrr or ifrp isn't defined as a numeric column in the table, you may consider to amend your code like this for,say ifrb:
strWHERE = "ifrf = " & cboFRAME & " and ifrb =[highlight]'[/highlight]" & cboBLOCK & "[highlight]'[/highlight] and ifrr = " & cboROW & " and ifrp = " & cboPAIR

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV,

The answer was in your first line. The selection form was using int. and the table was text. Changed the table to int and all was fixed.

Thanks,

Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top