Form.Filter Syntax

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • matt753
    New Member
    • May 2010
    • 91

    Form.Filter Syntax

    I want to impliment a button that filters and shows only records where the field "Performanc eID" has nothing in it.

    Currently have the following for filtering by date, I know the syntax is similar but I cant seem to get it right.

    Code:
    frmsubAdminEdit.Form.Filter = "ShippedDate=#" & txtDate.Value & "#"
  • Megalog
    Recognized Expert Contributor
    • Sep 2007
    • 378

    #2
    Code:
    frmsubAdminEdit.Form.Filter = "[ShippedDate] = #" & txtDate.Value & "# AND [PerformanceID] Is Null"

    Comment

    • matt753
      New Member
      • May 2010
      • 91

      #3
      I was just trying to do the one filter, not both, but that helped with the syntax. I tried:

      Code:
      frmsubAdminEdit.Form.Filter = [PerformanceID] Is Null
      But I get the error: Run Time error 2465: cant find the field '|' refferred to in your expression.

      I also have this line right after the previous cause I thought you need it:

      Code:
      frmsubAdminEdit.Form.FilterOn = True

      Comment

      • Megalog
        Recognized Expert Contributor
        • Sep 2007
        • 378

        #4
        The filter you're passing is a string, which in all cases needs to be encapsulated with double quotes like below:

        Code:
        frmsubAdminEdit.Form.Filter = "[PerformanceID] Is Null"

        Comment

        • matt753
          New Member
          • May 2010
          • 91

          #5
          Thanks that worked!

          On a similar note, how would I get a filter to display only records after a specific date? I've tried:
          Code:
          frmsubAdminEdit.Form.Filter = "[ShippedDate] > #01/01/10#"
          but that doesnt display all records after that date for some reason. Thinking it has something to do with the > symbol
          Last edited by NeoPa; May 10 '10, 10:58 PM. Reason: Please use the [CODE] tags provided

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32633

            #6
            No. What you have should be fine. I always use 4-digit years myself, but it should work that way nevertheless.

            Comment

            • matt753
              New Member
              • May 2010
              • 91

              #7
              It doesnt seem to be working to well, I will get entries from 05/03/2010 but not 05/10/2010

              Comment

              • Megalog
                Recognized Expert Contributor
                • Sep 2007
                • 378

                #8
                Is this a subform you're passing a filter to? If so, it may have a parent/child relationship that is limiting the records returned, regardless of the filter you're passing to it.

                Comment

                • matt753
                  New Member
                  • May 2010
                  • 91

                  #9
                  Yes it is a subform.

                  Would there be an easier way to do this then? Maybe with SQL or something?

                  What I need to do is show all records between 01/01/2010 and the current day, where the PerformanceID Is Null. This is the current code that doesnt work:
                  Code:
                  frmsubAdminEdit.Form.Filter = "[ShippedDate] > #01/01/2010# AND [ShippedDate] <= Date() AND [PerformanceID] Is Null"
                  This however does work:
                  Code:
                  frmsubAdminEdit.Form.Filter = "[ShippedDate] > #01/01/2010# AND [ShippedDate] <= Date()"

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32633

                    #10
                    Originally posted by matt753
                    I will get entries from 05/03/2010 but not 05/10/2010
                    What data do you get when you don't apply the filter?

                    Remember, that is the set of data your filter is applied to.

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32633

                      #11
                      Originally posted by matt753
                      This however does work:
                      Do the missing records have a [PerformanceID] value?

                      Another point - You can use the construct :
                      Code:
                      [ShippedDate] Between #01/01/2010# And Date()
                      This is just a neater and more efficient way to do the bit that is already working of course ;)

                      Comment

                      • matt753
                        New Member
                        • May 2010
                        • 91

                        #12
                        Originally posted by NeoPa
                        What data do you get when you don't apply the filter?

                        Remember, that is the set of data your filter is applied to.
                        When the filter isn't applied I get all of the records, which are descending by ShippedDate.

                        I thought it was a problem with the AND's in the filter syntax, does vba had AndAlso or OrElse like VB does?

                        Comment

                        • matt753
                          New Member
                          • May 2010
                          • 91

                          #13
                          Do the missing records have a [PerformanceID] value?
                          Yes

                          This is just a neater and more efficient way to do the bit that is already working of course ;)
                          Thanks!

                          Comment

                          • Megalog
                            Recognized Expert Contributor
                            • Sep 2007
                            • 378

                            #14
                            Originally posted by matt753
                            Do the missing records have a [PerformanceID] value?
                            Yes
                            Then Access, like usual, is doing exactly what you told it to do. You're not seeing those records because you're adding "[PerformanceID] Is Null" to the filter.

                            If you want the opposite, then use Is Not Null

                            Comment

                            • NeoPa
                              Recognized Expert Moderator MVP
                              • Oct 2006
                              • 32633

                              #15
                              Matt,

                              It's difficult to follow what you mean when you're not explicit, especially as you seem to jump between different situations.

                              Your post #12 was in response to my post #10, which in turn was a response to your post #7 - referring to your post #5 which is simply comparing the [ShippedDate] field to #01/01/10#. Since this earlier position, you've moved on to discuss a more complex WHERE clause which includes a start and end date, as well as checking [PerformanceID] for Null.

                              This makes a sensible conversation very difficult (It's naturally somewhat complicated already by trying to do it via a web page).

                              Can you confirm that simply applying the date filtering (Let's standardise on the Between version to avoid confusion) results in records being absent that are present when there is no filtering?

                              Comment

                              Working...