Filtering form records using a combo box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • novoselent
    New Member
    • Mar 2008
    • 3

    Filtering form records using a combo box

    This seems like it should be an easy thing, but I think I'm missing something simple here...or I'm just going about it all wrong...

    Using Access 2003

    I have a form that lists vehicle service dates for different company terminals.
    The form loads showing all records.

    In the form header I have a combo box named "CSCFilter" that is unbound, and uses the table/query option to list the 16 terminals in our company.

    The field I'm trying to filter in the details section is named "CSC"

    I'm trying to use the After Update event on the combo box to filter the form based on the selection made on the combo box.
    Basically what I have now is 16 identical forms, with each one sorting the CSC manually in the SQL statement...whi ch makes updating the form a pain because I have to make every little change 16x. I want to switch to one form, where I can cycle through the 16 terminals, simply by choosing them on the combo box.

    This is what I have in the After Update event:

    [code=vb]Private Sub CSCFilter_After Update()
    Me.Filter = "CSC = " & Me.CSCFilter
    Me.FilterOn = True
    End Sub[/code]

    Using this function will get the form to filter correctly, however it's not accepting the value in the combo box as the filter value...it's spitting up a dialog box asking me to enter in the parameter value, but the dialog box is changing it's name to the name selected in the combo box...if that makes any sense.

    What am I doing wrong?
    Last edited by JKing; Mar 1 '08, 07:20 AM. Reason: [CODE] Tags
  • novoselent
    New Member
    • Mar 2008
    • 3

    #2
    edited initial post...couldn't find the delete option

    Comment

    • Stewart Ross
      Recognized Expert Moderator Specialist
      • Feb 2008
      • 2545

      #3
      Originally posted by novoselent
      This seems like it should be an easy thing, but I think I'm missing something simple here......This is what I have in the After Update event:

      [code=vb]Private Sub CSCFilter_After Update()
      Me.Filter = "CSC = " & Me.CSCFilter
      Me.FilterOn = True
      End Sub[/code]
      Hi Novoselent. Your filter is very nearly right - but you are missing some quote marks from your filter string. Without these, you are not passing a string literal to the filter. The value from the combo box is being passed as if it was a field name - and because there is no match for that field it is asking you for the parameter value.

      Easy to fix - just change your Me.Filter statement to
      [code=vb]Me.Filter = "CSC = '" & Me.CSCFilter & "'"[/code]
      -Stewart

      Comment

      • novoselent
        New Member
        • Mar 2008
        • 3

        #4
        works like a charm!

        I was physically unable to walk away last night until I had it working...so I figured out how to do it, using a macro instead...but I liked my original approach so much better, much cleaner i think. nice to know I was close at least. Those quotes get me all the time...pesky things!

        Thanks for helping me get it working!

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32656

          #5
          Check out Example Filtering on a Form and Quotes (') and Double-Quotes (") - Where and When to use them for assistance with these issues.

          Comment

          Working...