Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2008
    Posts
    24

    Unanswered: Filtering in a form

    How can I use a combobox to filter information in a field using code
    I have a field called SalesAgent these are names I would like to be able to
    have all the records for the selected agent.

    Pehaps I could add a sample of the code

    Private Sub cboFindAgent_AfterUpdate()
    Me.Filter = Me.SalesAgent = "& cboFindAgent.Value"
    Me.FilterOn = True
    End Sub
    this is not working
    Last edited by sandrao; 04-07-08 at 14:18.

  2. #2
    Join Date
    Apr 2004
    Location
    Kingsland, Georgia
    Posts
    231
    Maybe

    Me.Filter = "SalesAgent='" & cboFindAgent.Value & "'"

    is your field in the table named SalesAgent

  3. #3
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Personally I'd avoid using the .Filter command and instead opt to set the recordsource query to a select statement such as:

    me.recordsource = "Select * from MyTable where SalesAgent = '" & me!cboFindAgent & "'" (for a string comparison)

    me.recordsource = "Select * from MyTable where SalesAgent = " & me!cboFindAgent & "" (for an integer comparison)

    I've had too many problems using the Filter command and the speed of it.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  4. #4
    Join Date
    Apr 2008
    Posts
    24
    Thanks

    the recordsource works fine

    I usually use filter when I an using the following
    Me.Filter = "[Month] Like 'Jul'"

    however the recordsource works like a charm

    thanks again

  5. #5
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Interesting... I don't have any trouble with filtering. It can be horribly slow when you're dealing with lots of records, but other than that, I haven't had problems with it?
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  6. #6
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    The slow part was my main complaint with using it.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  7. #7
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Ok

    Coz I use it quite a lot with tables that have small amounts of records
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •