Any ideas on why this code will not work when I enter a parameter in the Defect field in my form? I get a "Run-time error '3075' Syntax error in string expression". I borrowed this code from this website & I am not that familiar with it. It does work for any combination of the Machine, Review_By and Operator fields. Any help would be greatly appreciated. Thanks...
Option Compare Database
Private Sub command122_Click()
'Set the Dimensions of the Module
Dim strSQL As String, strOrder As String, strWhere As String
Dim dbNm As Database
Dim qryDef As QueryDef
Set dbNm = CurrentDb()
'Constant Select statement for the Query definition
strSQL = "SELECT * " & _
"FROM [tbl RA Data]"
strWhere = "WHERE"
strOrder = "ORDER BY [tbl RA Data].Date;"
'Set the WHERE clause for the QueryDef if information has been entered into a field on the form
If Not IsNull(Me.[Machine]) Then
strWhere = strWhere & " ([tbl RA Data].[Machine]) = '" & Me.[Machine] & "' AND"
End If
If Not IsNull(Me.[Review_By]) Then
strWhere = strWhere & " ([tbl RA Data].[Review_By]) = '" & Me.[Review_By] & "' AND"
End If
If Not IsNull(Me.[Operator]) Then
strWhere = strWhere & " ([tbl RA Data].[Operator]) Like '*" & Me.[Operator] & "*' AND"
End If
If Not IsNull(Me.[Defect]) Then
strWhere = strWhere & " ([tbl RA Data].[Current Defect]) Like '*" & Me.[Defect] & "*' OR ([tbl RA Data].[Current Prob Descr]) Like '*" & Me.[Defect] & "*' AND"
End If
'Remove the last AND from the SQL statment
strWhere = Mid(strWhere, 1, Len(strWhere) - 5)
'Pass the QueryDef to the query
Set qryDef = dbNm.QueryDefs("qry sort by")
qryDef.SQL = strSQL & " " & strWhere & "" & strOrder
'Open the Query
DoCmd.OpenQuery "qry sort by", acViewNormal
End Sub
Option Compare Database
Private Sub command122_Click()
'Set the Dimensions of the Module
Dim strSQL As String, strOrder As String, strWhere As String
Dim dbNm As Database
Dim qryDef As QueryDef
Set dbNm = CurrentDb()
'Constant Select statement for the Query definition
strSQL = "SELECT * " & _
"FROM [tbl RA Data]"
strWhere = "WHERE"
strOrder = "ORDER BY [tbl RA Data].Date;"
'Set the WHERE clause for the QueryDef if information has been entered into a field on the form
If Not IsNull(Me.[Machine]) Then
strWhere = strWhere & " ([tbl RA Data].[Machine]) = '" & Me.[Machine] & "' AND"
End If
If Not IsNull(Me.[Review_By]) Then
strWhere = strWhere & " ([tbl RA Data].[Review_By]) = '" & Me.[Review_By] & "' AND"
End If
If Not IsNull(Me.[Operator]) Then
strWhere = strWhere & " ([tbl RA Data].[Operator]) Like '*" & Me.[Operator] & "*' AND"
End If
If Not IsNull(Me.[Defect]) Then
strWhere = strWhere & " ([tbl RA Data].[Current Defect]) Like '*" & Me.[Defect] & "*' OR ([tbl RA Data].[Current Prob Descr]) Like '*" & Me.[Defect] & "*' AND"
End If
'Remove the last AND from the SQL statment
strWhere = Mid(strWhere, 1, Len(strWhere) - 5)
'Pass the QueryDef to the query
Set qryDef = dbNm.QueryDefs("qry sort by")
qryDef.SQL = strSQL & " " & strWhere & "" & strOrder
'Open the Query
DoCmd.OpenQuery "qry sort by", acViewNormal
End Sub