Results 1 to 6 of 6
  1. #1
    booismycat is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2014
    Posts
    12

    DoCmd.OpenReport Filter Question

    I have a form that uses an option group (radio buttons) which allows the user to select a specific filter for a report.
    The default is ALL records using the following:

    DoCmd.OpenReport "ChecksByCategory", acViewReport

    When the user selects something other than ALL, my code will convert the option value of the radio button to a string that I use as the option label.

    DoCmd.OpenReport "ChecksByCategory", acViewReport, , "Category = " & myFilter




    My problem: One option is to report on all records where Category is null and I can't get this to work. No matter how I code this, when Access does not error on my syntax (for is null), I get a blank report. All other options work. I have tried every variation of [Category] is Null that I can think of with no luck to date.
    To work around this, I duplicated ChecksByCategory, modified the query to [Category] is null and named the report ChecksNoCategory.

    How can I get my DoCmd.OpenReport to recognize "Is Null"?

    Thank you

  2. #2
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    One way,

    IF ISNULL(Me!myFilter) THEN
    DoCmd.OpenReport "ChecksByCategory", acViewReport
    ELSE
    DoCmd.OpenReport "ChecksByCategory", acViewReport, , "Category = " & myFilter
    END IF

  3. #3
    booismycat is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2014
    Posts
    12
    Not sure you understand my issue as this is what I have tried and it does not resolve the issue.
    When myFilter = "Is Null" or myFilter = "Not Is Null" the results are a blank report, which is not correct.

    I guess my question is: How would I set myFilter to equal <Is Null> or <Not Is Null> without it being seen as a String because this seems to be what is happening.

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Things are not equal to null ( myFilter = "Is Null")
    it has to be in the function IsNull([field])

    SOMETIMES you can get results by using the empty set: [myField] = "" (instead of using the NULL)

  5. #5
    booismycat is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2014
    Posts
    12
    Yeah, I'm aware that "Is Null" is a string... and not the condition I need.
    I still believe I should be able to set myFilter to Is Null so that - DoCmd.OpenReport "ChecksByCategory", acViewReport, , "Category = " & myFilter works properly.
    WHERE ((Category) is null) - IS a valid SQL statement within MSAccess.

  6. #6
    booismycat is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2014
    Posts
    12
    I resolved my problem.

    First, I set my function to be a variant
    Function CategoryFilter() As Variant

    This allowed me to eliminate the quotes that were seen as defining a string.
    I then had to create an IF statement because the valid SQL WHERE statement in the docmd.openreport statement does not like the = sign when using the Is Null or/and the Not Is Null.

    Thanks for the input.

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

Similar Threads

  1. DoCmd.OpenReport Where Argument
    By snipe in forum Programming
    Replies: 2
    Last Post: 04-24-2014, 10:24 AM
  2. DoCmd.OpenReport WHERE condition
    By bidbud68 in forum Programming
    Replies: 16
    Last Post: 10-19-2012, 05:31 AM
  3. Need help w/ docmd.openreport
    By jwill in forum Reports
    Replies: 3
    Last Post: 06-04-2012, 09:49 PM
  4. Replies: 2
    Last Post: 10-13-2011, 09:14 AM
  5. DoCmd OpenReport ... where condition with a Like
    By Grooz13 in forum Programming
    Replies: 4
    Last Post: 08-31-2010, 09:04 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