Multiple Criteria Form problem

  • Thread starter Thread starter k4an611
  • Start date Start date
K

k4an611

I am trying to create a multiple criteria form. I am using the followin
code that was adapted from a tutorial. I am getting a "Syntac Error i
From clause" error. Can anyone see a reason why this is happening. I a
new to access.

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 o
the SQL
' statements and removes it if it exists. This prevents a "synta
error."
If Right(sSQL, 3) = "ND " Then
sLen = Len(sSQL)
sSQL = Left(sSQL, sLen - 4)
End If
Forms![browse_products].Form.RecordSource = sSQL
End Su
 
You're missing the WHERE statement:

Code
-------------------

sSQL = sSQL & " WHERE (((Products.NDC_Number)=[Forms]![QBF_Form]![NDC_Number])) AND "
End If
If Not IsNull(Me.ProductName) Then
sSQL = sSQL & " WHERE (((Products.ProductName)=[Forms]![QBF_Form]![ProductName])) AND "
 
Back
Top