Results 1 to 5 of 5
  1. #1
    dharmacloud is offline Novice
    Windows Vista Access 2007
    Join Date
    Aug 2011
    Posts
    21

    Error with filtering subform using 2 combo boxes


    Hi all,

    I have made a form with 2 comboboxes: Year and Term to filter the results for a subform containing student courses. It seems to filter the year without any trouble but when I go to Term combobox and choose the term, it gives me this error message: Run-time error ‘3075’: Syntax error in string in query expression ‘[CourseYear] = 2010 AND [Term]= Spring”

    Can anyone help me figure out what's wrong with my code? Attached is screenshot of my form/subform. Here's the code, that I'm using:

    Code:
    Private Function SetSubFormFilter()
    
       Dim mFilter As String
       mFilter = ""
    
       If Not IsNull(Me.Combo180) Then
          mFilter = " [CourseYear] = " & Me.Combo180.Value
       End If
    
       If Not IsNull(Me.Combo182) Then
         If Len(mFilter) > 0 Then mFilter = mFilter & " AND "
         mFilter = mFilter & "[Term]= " & Me.Combo182 & "'"
       End If
    
         If Len(mFilter) > 0 Then
           Me.TestCourseRegistration.Form.Filter = mFilter
           Me.TestCourseRegistration.Form.FilterOn = True
       Else
           Me.TestCourseRegistration.Form.FilterOn = False
       End If
    
       Me.TestCourseRegistration.Form.Requery
       DoEvents
    
    End Function
    
    Private Sub Command184_Click()
       Me.TestCourseRegistration.Form.FilterOn = False
       Me.TestCourseRegistration.Form.Requery
       DoEvents
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Try

    mFilter = mFilter & "[Term]= '" & Me.Combo182 & "'"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Just looking at your error message, I think this:
    ‘[CourseYear] = 2010 AND [Term]= Spring”

    . . . should be interpreted by Access to read:
    [CourseYear] = 2010 AND [Term]= "Spring”

    The problem lies generally in how you've constructed your filter string and, specifically, in not passing the quotation marks required for the string that represents Term.

    I hope this points you in the right direction.

    You have to pass the contents of Combo182 couched in double quotation marks.

    Let us know if that helps.

  4. #4
    dharmacloud is offline Novice
    Windows Vista Access 2007
    Join Date
    Aug 2011
    Posts
    21
    Thanks so so much Paul! I copied and paste your code and it worked!!! You're the greatest!

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 9
    Last Post: 06-04-2014, 10:45 AM
  2. Filtering options using Cascading Combo boxes
    By Lincoln in forum Database Design
    Replies: 3
    Last Post: 07-15-2011, 08:25 PM
  3. cascading combo boxes in continuous subform
    By ayamali in forum Programming
    Replies: 1
    Last Post: 03-29-2011, 06:33 PM
  4. Filtering a Subform
    By swalsh84 in forum Programming
    Replies: 2
    Last Post: 06-23-2010, 10:51 PM
  5. Replies: 0
    Last Post: 08-17-2008, 12:19 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