I am trying to run this code on a form open - that askes for the search criteria, then just brings up the specific records, but i am getting Error 3075
"Syntax error (Missing operator) in the query expression as per image below.
If i click on OK, the code runs but does not recognise the names of some of the join fields.
"Syntax error (Missing operator) in the query expression as per image below.
If i click on OK, the code runs but does not recognise the names of some of the join fields.
Code:
Private Sub Form_Open(Cancel As Integer)
Dim Search As String
Dim Strsql As String
On Error GoTo Handler
Search = Trim(InputBox("Enter Line Number . . . ", "Search Line"))
If StrPtr(Search) = 0 Then
MsgBox ("User Canceled!")
ElseIf Search = vbNullString Then
MsgBox "No Data!", vbExclamation + vbOKOnly, "Cancelled"
Else
Strsql = "SELECT DISTINCT tblWarehouseStock.Cat_No, tblproducts.Line_Description, Sum(tblWarehouseStock.No_Items) AS SumOfNo_Items, tblWarehouseStock.Status_ID, tblproducts.Size_Description " & vbCrLf & _
"FROM tblWarehouseStock LEFT JOIN tblproducts ON tblWarehouseStock.Cat_No = tblproducts.Cat_No " & vbCrLf & _
"GROUP BY tblWarehouseStock.Cat_No, tblproducts.Line_Description, tblWarehouseStock.cat_no, tblWarehouseStock.Status_ID, tblproducts.Size_Description " & vbCrLf & _
"WHERE tblWarehouseStock.cat_no='" & Trim(UCase(Nz(Search, ""))) & "' ;"
'Debug.Print Strsql
End If
Me.RecordSource = Strsql
Exit Sub
Handler:
Call LogError(Err.Number, Err.Description, "11", "")
Exit Sub
End Sub