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