Results 1 to 6 of 6
  1. #1
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328

    Filter using OR when one of values is null

    I have a form with two pulldowns. The user can select number values in the pulldowns, then click a button to filter the form to either or both values. Problem is , if one of the pulldowns is null, I get an error message. I have an identical set up wherein the pulldowns are text values and do not get an error message when one is null.

    I can put in some code to ignore one of pulldowns if it is null, but wonder if there is something simpler that I am missing. Any help much appreciated.

    Code:

    Me.FilterOn = True
    Dim phrf1 As Long
    phrf1 = Me.PHRFbox1

    Dim phrf2 As Long
    phrf2 = Me.phrfBox2



    Me.Filter = "phrf=" & phrf1 & " Or phrf = " & phrf2 & ""

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,630
    Conditional code is probably best approach. Review http://www.allenbrowne.com/ser-62code.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    Quote Originally Posted by June7 View Post
    Conditional code is probably best approach. Review http://www.allenbrowne.com/ser-62code.html
    Thanks for quick reply. I was hoping to avoid the extra code, but glad to know that I just didn't overlook something. . Funny that code is happy to ignore nulls with text values, but not with number values.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,630
    Does your code for the text pulldowns use LIKE operator and wildcard?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Another solution might be to use the Nz function to give you a number (that you know will never match) when the pulldowns are Null. For example, if the pulldowns have only positive numbers to select from, then you could have the Nz return -1, like this:

    phrf1 = nz(Me.PHRFbox1,-1)
    and
    phrf2 = nz(Me.PHRFbox2,-1)

    When you declare a variable as anything other than Variant, and then attempt to assign a Null to it, you will usually get an error.

    John

  6. #6
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    Solved. I had declared it as variant before and still got the error. However, the nz declaration works. The data does contain minus numbers, but never an entry less than -100 or thereabouts, so by using -300 instead of -1, problem solved Thank you very much.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Filter fields including records with null
    By Ruegen in forum Programming
    Replies: 18
    Last Post: 01-28-2014, 11:23 PM
  2. Replies: 4
    Last Post: 01-14-2014, 01:28 PM
  3. Replies: 7
    Last Post: 12-04-2013, 01:55 PM
  4. Finding the Max Date and Null Values if Null
    By SpdRacerX in forum Queries
    Replies: 1
    Last Post: 02-03-2012, 06:29 AM
  5. null values
    By ippy in forum Queries
    Replies: 3
    Last Post: 12-20-2010, 10:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums