Results 1 to 3 of 3

Syntax Error (missing operator) in query expression

  1. #1
    johndoe123 is offline Novice
    Windows 10 Access 2007
    Join Date
    May 2019
    Posts
    2

    Syntax Error (missing operator) in query expression

    I am doing a search button that displays the record based on on my data in a table called Stock_Master.
    The Stock_Master Data Type are


    Product_Id = Number
    Category = Text
    Type = Text
    Size = Text
    Total_Quantity = Number

    The following are my VBA code for the button:

    Dim strsearch As String
    Dim strText As String


    strText = Me.StockMasterSize.Value
    strsearch = "select * from Stock_Master where ((Size like " & strText & "))"
    Me.RecordSource = strsearch (highlithe when debug)


    End Sub


    However, the error-code appears when I search for the data 1 Lt in the textbox and clicked the button that is:

    Syntax Error (missing operator) in query expression '((size like 1 Lt))'


    I used similar coding for another search button and it worked but not this.
    PLEASE HELP!

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,711
    If it is a text value (which it is), it needs to be surrounded in quotes, i.e.
    Code:
    strsearch = "select * from Stock_Master where Size like '" & strText & "'"
    Using Access 2007
    Proficient in Access, Excel, VBA, and SQL

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    8,214
    Note that "Size" and "Type" are reserved words in Access and shouldn't be used for object names.



    See http://allenbrowne.com/AppIssueBadWord.html for a list of reserved words.
    HTH
    -----
    Steve
    --------------------------------
    "Veni, Vidi, Velcro"
    (I came; I saw; I stuck around.)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 11-07-2017, 06:26 PM
  2. Replies: 5
    Last Post: 10-25-2017, 01:47 PM
  3. Replies: 4
    Last Post: 03-16-2016, 12:24 PM
  4. Replies: 2
    Last Post: 02-17-2014, 10:27 AM
  5. Replies: 9
    Last Post: 01-22-2013, 04:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Tech Forums: Microsoft Office Forums