Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Sep 2002
    Location
    London, England
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can't set form filter to empty string (2000)

    I use the code below to set a form's Filter property. It works fine until the variable strF contains an empty string. When this happens the line Me.Filter = strF seems to be ignored and I am always left with whatever the previous filter was. Me.Filter doesn't accept Null. Is there some other way of emptying it? I know I could turn the filter off but this seems to a sledgehammer to crack a nut.

    Me.Filter = strF
    Me.FilterOn = True
    Me.txtFilter = Me.Filter

    Ian

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Can't set form filter to empty string (2000)

    You cannot set the Filter property to Null, but you *can* set it to the empty string "". This automatically sets FilterOn to False.

    If you set FilterOn to False by itself, the Filter property will remain intact, but inactive. You can reactivate it by setting FilterOn to True again.

  3. #3
    3 Star Lounger
    Join Date
    Sep 2002
    Location
    London, England
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can't set form filter to empty string (2000)

    I know that's the theory but I find that it sometimes doesn't work and wondered if there was a known bug.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Can't set form filter to empty string (2000)

    Setting Me.Filter = "" is supposed to be "the" way to remove a filter. I haven't experienced problems with it, but then I don't use Access 2000.

    I don't see why setting Me.FilterOn = False is a "sledgehammer approach" - you can use either that or DoCmd.ShowAllRecords to turn off the filter. As I wrote before, this will NOT clear the Filter property, only deactivate it.

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Can't set form filter to empty string (2000)

    You can't *change* a filter midstream without turning the FilterOn property off first, if that's what you're trying to do.
    Charlotte

  6. #6
    3 Star Lounger
    Join Date
    Sep 2002
    Location
    London, England
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can't set form filter to empty string (2000)

    Yes, that's what I was doing. I didn't realise there was a problem. Do you mean I have to do the following when changing a form's filter?

    1) Create new filter string
    2) Set FilterOn to false
    3) Assign new filter string to Me.Filter
    4) Set FilterOn to True.

    I haven't done this in the past because, up to the current problem, changing the Me.Filter property on the fly has always worked. If I follow the above approach, will I have to stop the form from refreshing until I have finished?

    Ian

  7. #7
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Can't set form filter to empty string (2000)

    The nature of some of the properties changed between 97 and 2000. Properties that were variants became strongly typed as strings, and I believe that Filter was one of those. I haven't been able to make 2000 change form filters on the fly without first turning off the filteron property and then changing the filter and turning filteron back on. Perhaps someone else has found a secret that I haven't discovered.
    Charlotte

Posting Permissions

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