All,
I am getting the following error with the code below:
Run-time error '3129';
Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE',
The code I am using that is getting this error is below:
Private Sub cmdSearch_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 tbl_test.MainID, tbl_test.field1, tbl_test.field2, tbl_test.field3, tbl_sub1.MainID, tbl_sub1.fieldA1, tbl_sub1.fieldA2, tbl_sub2.MainID, tbl_sub2.fieldB1, tbl_sub2.fieldB2" & _
strSQL = "FROM (tbl_test INNER JOIN tbl_sub1 ON tbl_test.MainID = tbl_sub1.MainID) INNER JOIN tbl_sub2 ON tbl_sub1.MainID = tbl_sub2.MainID"
strWhere = "WHERE (((tbl_sub1.fieldA1)"
strOrder = "ORDER BY tbl_test.MainID;"
'Set the WHERE clause for the QueryDef if information has been entered into a field on the form
If Not IsNull(Me.field1) Then '<--If the textbox field1 contains no data THEN do nothing
strWhere = strWhere & " (tbl_test.field1) Like '*" & Me.field1 & "*' AND" '<--otherwise, apply the LIKE statment to the QueryDef
End If
If Not IsNull(Me.field2) Then
strWhere = strWhere & " (tbl_test.field2) Like '*" & Me.field2 & "*' AND"
End If
If Not IsNull(Me.field3) Then
strWhere = strWhere & " (tbl_test.field3) Like '*" & Me.field3 & "*' AND"
End If
If Not IsNull(Me.fieldA1) Then
strWhere = strWhere & " (tbl_sub1.fieldA1) Like '*" & Me.fieldA1 & "*' AND"
End If
If Not IsNull(Me.fieldA2) Then
strWhere = strWhere & " (tbl_sub1.fieldA2) Like '*" & Me.fieldA2 & "*' 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_test"
qryDef.SQL = strSQL & " " & strWhere & "" & strOrder
'Open the Query
DoCmd.OpenReport "rpt_test", acViewPreview, "", "", acNormal
End Sub
Can someone please help,
Jerome Benton
JERPAT Web Designs
GOD Is Good All The Time!!!
I am getting the following error with the code below:
Run-time error '3129';
Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE',
The code I am using that is getting this error is below:
Private Sub cmdSearch_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 tbl_test.MainID, tbl_test.field1, tbl_test.field2, tbl_test.field3, tbl_sub1.MainID, tbl_sub1.fieldA1, tbl_sub1.fieldA2, tbl_sub2.MainID, tbl_sub2.fieldB1, tbl_sub2.fieldB2" & _
strSQL = "FROM (tbl_test INNER JOIN tbl_sub1 ON tbl_test.MainID = tbl_sub1.MainID) INNER JOIN tbl_sub2 ON tbl_sub1.MainID = tbl_sub2.MainID"
strWhere = "WHERE (((tbl_sub1.fieldA1)"
strOrder = "ORDER BY tbl_test.MainID;"
'Set the WHERE clause for the QueryDef if information has been entered into a field on the form
If Not IsNull(Me.field1) Then '<--If the textbox field1 contains no data THEN do nothing
strWhere = strWhere & " (tbl_test.field1) Like '*" & Me.field1 & "*' AND" '<--otherwise, apply the LIKE statment to the QueryDef
End If
If Not IsNull(Me.field2) Then
strWhere = strWhere & " (tbl_test.field2) Like '*" & Me.field2 & "*' AND"
End If
If Not IsNull(Me.field3) Then
strWhere = strWhere & " (tbl_test.field3) Like '*" & Me.field3 & "*' AND"
End If
If Not IsNull(Me.fieldA1) Then
strWhere = strWhere & " (tbl_sub1.fieldA1) Like '*" & Me.fieldA1 & "*' AND"
End If
If Not IsNull(Me.fieldA2) Then
strWhere = strWhere & " (tbl_sub1.fieldA2) Like '*" & Me.fieldA2 & "*' 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_test"
qryDef.SQL = strSQL & " " & strWhere & "" & strOrder
'Open the Query
DoCmd.OpenReport "rpt_test", acViewPreview, "", "", acNormal
End Sub
Can someone please help,
Jerome Benton
JERPAT Web Designs
GOD Is Good All The Time!!!