Results 1 to 4 of 4
  1. #1
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA novice - multiple filters

    The only VBA I know is mainly through looking at expression builder code and adapting it to try and suit my needs. I also have a couple of books. However, I can't seem to find how to get a filter on two fields working:

    The user selects a filter option in 2 boxes (unbound) and then clicks on an "apply filter" button.

    I tried to put the following code in:
    DoCmd.ApplyFilter , "[CampaignCode]= forms![frmtelesales01]![Campaign Filter]"
    DoCmd.ApplyFilter, "[LEA]= forms![frmtelesales01]![LEA Filter]"

    However, the second filter replaced the first, instead of adding to it. How do I apply both filters at the same time?

    Any help would be much appreciated.

  2. #2
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA novice - multiple filters

    Additional...........

    The first time I enter the form, the filter boxes are empty.
    How do I make the boxes blank again after a filter has been removed? At the moment the box will show that a selection has been made even though no filter is applied.

  3. #3
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: VBA novice - multiple filters

    Hi Phil,
    I think what you want is:
    DoCmd.ApplyFilter , "[CampaignCode]= forms![frmtelesales01]![Campaign Filter] AND [LEA]= forms![frmtelesales01]![LEA Filter]"
    As regards clearing the textboxes, I'd suggest just adding a clear filter button which removes the filter and also sets [CampaignCode] = "" and [LEA] = ""
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  4. #4
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA novice - multiple filters

    Thanks very much Rory.
    I had tried the line below, but because I had the quotes at the end and beginning of each filter it didn't work.....so close, yet so far away.

    DoCmd.ApplyFilter , "[CampaignCode]= forms![frmtelesales01]![Campaign Filter]" AND "[LEA]= forms![frmtelesales01]![LEA Filter]"

Posting Permissions

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