KellyNewUser
Technical User
Hi, I am trying to create a form with multiple criteria. I am adapting the code below from a tutorial. I am getting an error for "Syntax error in From Clause". Can anyone see a reason for this.
Kelly
Private Sub Command19_Click()
Dim sSQL As String, sLen As Integer
sSQL = "SELECT products.* FROM Products"
If Not IsNull(Me.NDC_Number) Then
sSQL = sSQL & "(((Products.NDC_Number)=[Forms]![QBF_Form]![NDC_Number])) AND "
End If
If Not IsNull(Me.ProductName) Then
sSQL = sSQL & " (((Products.ProductName)=[Forms]![QBF_Form]![ProductName])) AND "
DoCmd.OpenForm "browse_products"
End If
' The following "IF...then" sequence detects for "AND" at the end of the SQL
' statements and removes it if it exists. This prevents a "syntax error."
If Right(sSQL, 3) = "ND " Then
sLen = Len(sSQL)
sSQL = Left(sSQL, sLen - 4)
End If
Forms![browse_products].Form.RecordSource = sSQL
End Sub
Kelly
Private Sub Command19_Click()
Dim sSQL As String, sLen As Integer
sSQL = "SELECT products.* FROM Products"
If Not IsNull(Me.NDC_Number) Then
sSQL = sSQL & "(((Products.NDC_Number)=[Forms]![QBF_Form]![NDC_Number])) AND "
End If
If Not IsNull(Me.ProductName) Then
sSQL = sSQL & " (((Products.ProductName)=[Forms]![QBF_Form]![ProductName])) AND "
DoCmd.OpenForm "browse_products"
End If
' The following "IF...then" sequence detects for "AND" at the end of the SQL
' statements and removes it if it exists. This prevents a "syntax error."
If Right(sSQL, 3) = "ND " Then
sLen = Len(sSQL)
sSQL = Left(sSQL, sLen - 4)
End If
Forms![browse_products].Form.RecordSource = sSQL
End Sub