Results 1 to 4 of 4
  1. #1
    heinensk23 is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2011
    Posts
    13

    Run-time error 3075

    I am getting an error



    Run-time error 3075
    Syntax error (missing operator) in query expression
    '[Menu_Toast_Name] = 'Beef's Food' AND [Brand] = 'Beef O Bradys".


    from this part of code


    Private Sub casc_cmbo_FSC_MENU_AfterUpdate()


    Dim myCascMenu As String
    myCascMenu = "Select * from tbl_FSC_ITEM_SETUP where [Menu_Toast_Name] = '" & Me.casc_cmbo_FSC_Menu & "' AND [Brand] = '" & Me.casc_cmbo_FSC_BRAND & "'"
    Me.subfrm_FSC_ITEM_SETUP.Form.RecordSource = myCascMenu
    Me.subfrm_FSC_ITEM_SETUP.Form.Requery


    End Sub

    The weird thing is it was working until I added more data to the main table. The error only shows when the new data is there. If I remove it, I don't get the error anymore.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Caused by the apostrophe in Beef's I suspect.?
    You would get the same problem with O'Grady ?

    Try 3 " """ instead of the single quote ' wherever that is used.

    Alternatively remove the single quote from the data with Replace()

    Put the criteria into a string variable, so you can debug.print it, and then when correct, use that in the sql ?
    Last edited by Welshgasman; 11-01-2021 at 12:11 PM.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    As WGMan points out it is the apostrophies that are breaking your code.
    You need to use multiple double quotes to deal with it.
    Something like:

    Code:
    myCascMenu = "Select * from tbl_FSC_ITEM_SETUP where [Menu_Toast_Name] = """ & Me.casc_cmbo_FSC_Menu & """ AND [Brand] = """ & Me.casc_cmbo_FSC_BRAND & """"
    You could also use a helper function to delimit the text fields.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  4. #4
    heinensk23 is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2011
    Posts
    13
    That was it.
    It is working now.
    Thanks!

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

Similar Threads

  1. Replies: 6
    Last Post: 02-03-2020, 07:09 PM
  2. Replies: 13
    Last Post: 05-31-2019, 10:48 PM
  3. Replies: 2
    Last Post: 01-04-2016, 09:40 AM
  4. Replies: 11
    Last Post: 05-01-2014, 11:56 AM
  5. Replies: 6
    Last Post: 05-30-2012, 12:32 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
  •  
Other Forums: Microsoft Office Forums