Results 1 to 4 of 4
  1. #1
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544

    The quotes are killing me!

    Hello! Happy Thanksgiving everyone!



    I keep getting a syntax error with this:
    Code:
      Private Sub Combo138_AfterUpdate()
    On Error GoTo Combo138_AfterUpdate_Err
    Debug.Print Combo138.Column(2)
    Debug.Print Combo138.Column(3)
        DoCmd.SearchForRecord , "", acFirst, " [memberid] = " & Combo138.Column(2) And "[PrimaryLotNum] = " & "'" & Combo138.Column(3) & "'"
        '"[PrimaryLotNum] = " & "'" & Screen.ActiveControl & "'"
    'WHERE ([AccountName]='" & Me.cboAccount & "'"
    Combo138_AfterUpdate_Exit:
        Exit Sub
    Combo138_AfterUpdate_Err:
        MsgBox Err.Description, vbCritical
        Resume Combo138_AfterUpdate_Exit  ERROR HIGHLIGHTS HERE
    End Sub
    The memberid is a number and the lot number is text. I'm using a combo box to find the member and their respective lot number (some members have more than one lot and assessment). My debugs print the correct information. I know my issue is with the quotes. TIA!

    Click image for larger version. 

Name:	combobox.png 
Views:	10 
Size:	47.6 KB 
ID:	36281

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    use filter:

    sWhere = "[memberid] = " & Combo138.Column(2) & " And [PrimaryLotNum] = '" & Combo138.Column(3) & "' and [PrimaryLotNum] ='" & Screen.ActiveControl & "'"
    docmd.filter = sWhere
    docmd.FilterOn = true

  3. #3
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,043
    Hi, the rule is simple: the where clause is a string and has to be surrounded by quotes:
    "MemberID = 1" Result: MemberID = 1

    If you have a text argument, you have to send literal quotes in the string. 2 following quotes are translated in 1 literal quote
    "MemberID = 1 and PrimaryLotNumber = ""ABC""" Result : MemberID = 1 and PrimaryLotNumber = "ABC"

    If you want to use variables for the criteria you have to bring them out of the string and concatenate the partial strings
    "MemberID = " & Combo138.Column(2) & " and PrimaryLotNumber = """ & Combo138.Column(3) & """"

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    try also adding something like
    Code:
    Dim strCriteria As String
    strCriteria = "[memberid] = " & Combo138.Column(2) And "[PrimaryLotNum] = " & "'" & Combo138.Column(3) & "'"
    Debug.Print strCriteria
    This makes it much easier to confirm that your criteria is correct and the delimiters are in the right places.

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

Similar Threads

  1. Function Killing Query Speed - PLEASE HELP!
    By archie1_za in forum Programming
    Replies: 28
    Last Post: 11-30-2017, 11:38 PM
  2. Please help this Access class is killing me
    By NovicetoAccess in forum Access
    Replies: 1
    Last Post: 07-14-2015, 12:53 PM
  3. I never know how many quotes to use!!
    By crombiecrunch in forum Modules
    Replies: 2
    Last Post: 05-12-2014, 07:54 AM
  4. This Relationship is killing me
    By minnetonka in forum Access
    Replies: 1
    Last Post: 05-02-2011, 10:31 AM
  5. Killing open applications using VBA
    By zippy483 in forum Programming
    Replies: 4
    Last Post: 03-03-2010, 10:04 PM

Tags for this Thread

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