Results 1 to 4 of 4
  1. #1
    Samson is offline Novice
    Windows 10 Access 2019
    Join Date
    Jun 2023
    Location
    Bristol, England
    Posts
    7

    Question 'IIf(IsNull(' in query not working.

    I have a report driven by a query. The query is called by a form that captures certain criteria for the query.



    I would like the query to ascertain whether the criteria entered is Null and if so replace the criteria in the query with the 'Like "*"' command.

    This is the line from the query:
    IIf(IsNull([Forms]![frmCardPaymentReportCriteria]![ReferenceType]),([tblCardPayment].[ReferenceType]) Like "*",[Forms]![frmCardPaymentReportCriteria]![ReferenceType])

    For the life of me I cannot get this to work. If the form criteria contains data the report works as expected, but if it is Null I see no records at all.

    The '[frmCardPaymentReportCriteria]![ReferenceType]' is a ComboBox which is set to Null in the Form-Load event of the criteria collection form.

    I have also used a Text Box on the form which is set to Null in the Form_Load event and not touched as the value from the form in the 'IIf' statement and it still does not work.
    IIf(IsNull([Forms]![frmCardPaymentReportCriteria]![TestText]),([tblCardPayment].[ReferenceType]) Like "*",[Forms]![frmCardPaymentReportCriteria]![ReferenceType])

    I have also tried to use a Check Box on the form which looks like this in the query:
    IIf([Forms]![frmCardPaymentReportCriteria]![chkAll],([tblCardPayment].[ReferenceType]) Like "*",[Forms]![frmCardPaymentReportCriteria]![ReferenceType])

    I'm racking my brains here as I've spent most of the day trying work out where I've gone wrong but I can't see my mistake. Any help would be very much appreciated.

    Thanks.

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Remove the IIf() function completely in the criteria and use

    Code:
    = [Forms]![frmCardPaymentReportCriteria]![ReferenceType] or [Forms]![frmCardPaymentReportCriteria]![ReferenceType]  Is Null
    

    This will automatically evaluate the second clause to true if the control is null, and return all the records, and is much more efficient than using the wildcard.
    Note the space between the
    Is Null - it's a different expression to the vba function IsNull()
    Last edited by Minty; 06-19-2023 at 08:30 AM.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi
    I would think that if your Control ReferenceType is Null you would have to specify a specific value to replace it with and
    not use a Wildcard
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  4. #4
    Samson is offline Novice
    Windows 10 Access 2019
    Join Date
    Jun 2023
    Location
    Bristol, England
    Posts
    7
    Absolutely fantastic. Worked first time. You're a genius. Thanks.

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

Similar Threads

  1. Query Critera - IsNull - Not working
    By tsgtnissen in forum Access
    Replies: 3
    Last Post: 09-10-2020, 11:09 AM
  2. VBA code for "Not IsNull" is not working
    By Xarkath in forum Access
    Replies: 11
    Last Post: 09-02-2014, 12:05 PM
  3. IsNull problem in query
    By excelhk in forum Queries
    Replies: 2
    Last Post: 04-08-2014, 03:59 AM
  4. IsNull not working
    By vbjohn in forum Access
    Replies: 19
    Last Post: 02-29-2012, 02:21 PM
  5. IsNull not working...
    By Moekandu in forum Programming
    Replies: 3
    Last Post: 01-29-2011, 06:48 PM

Tags for this Thread

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