Results 1 to 5 of 5
  1. #1
    MLo is offline Novice
    Windows 10 Office 365
    Join Date
    Jun 2020
    Posts
    3

    Form/Query handling NULL values

    Hello,



    I have a form which refers to a query I have which looks at a couple of related tables.

    Right now the form has a list box which shows the results of the query. The form also has a handful of text boxes, which, when data is entered into them, the query is re-run and the results in the list box are updated to reflect those values. The criteria in the query are mainly like this for several fields: Like '*' & [Forms]![FormName]![TextBox] & '*'. All of this works fine. However, one of the main tables the query is running against has some NULL values in some of the fields. For example, there is a date field and the query criteria is something like this: >=[Forms]![FormName]![DateTextBox].

    The problem I'm running into is that any of the records that contain a null in this date field are being excluded from the list box even before any data is entered into the search box. I can certainly go into the query and modify it to include "OR IS NULL", however then when some data is entered in the text box it won't then filter out the null value rows from the list box.

    I guess my question boils down to this: How can I get my query/list box to return all data for a given field until some data is entered into the search box, then, only display the data matching what was entered into the search box? Is this possible or am I trying to go about it the wrong way and there is some other better way to go about it? I'm open to suggestions.

    Thank you for taking the time to read my question and for any possible help!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I prefer not to use dynamic paramterized query. I use VBA to conditionally build filter criteria. If value is not entered in search control, then it is not included.

    But if you want parameterized query, try: WHERE ([fieldname] >= [Forms]![FormName]![DateTextBox] OR [Forms]![FormName]![DateTextBox] IS NULL)
    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
    MLo is offline Novice
    Windows 10 Office 365
    Join Date
    Jun 2020
    Posts
    3
    Quote Originally Posted by June7 View Post
    I prefer not to use dynamic paramterized query. I use VBA to conditionally build filter criteria. If value is not entered in search control, then it is not included.

    But if you want parameterized query, try: WHERE ([fieldname] >= [Forms]![FormName]![DateTextBox] OR [Forms]![FormName]![DateTextBox] IS NULL)
    Thank you very much for the response. It looks like, based on the example you've provided through the link that the entire data set is being built through the form and not referencing a query at all. I see the code you've applied to build the modifications to the criteria as it's filled out, and those are assigned to the filter buttons, so that's helpful. What I don't understand is if it's possible to apply this method to reference and update the parameters to the query that I've built?

    Regarding your second recommendation, I've already tried that, but of course it then doesn't filter out the NULL values once some search criteria has been entered into the search box.

    If you're interested to review what I've done so far, I've shared my database here: http://gofile.me/2UQG1/eDMapMUuA It's still in the build stage and doesn't have any important data in it yet.

    I very much appreciate your reply and help so far. I'm just trying to build out a small personal project, but while I have some SQL background, I am not experienced with Access/VBA at all.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Post 3 was moderated, I'm posting to trigger email notifications.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    MLo is offline Novice
    Windows 10 Office 365
    Join Date
    Jun 2020
    Posts
    3
    So I went back and tried this: WHERE ([fieldname] >= [Forms]![FormName]![DateTextBox] OR [Forms]![FormName]![DateTextBox] IS NULL)
    And although it seemed to me like it would do the same as what I already tried (adding OR IS NULL) the each variable in the WHERE statement, it did exactly what I was looking for it to do. I understand that this is looking at the field rather than the data in the table, but I still don't exactly understand why it works how I want it to.

    Anyway, thank you so much for your help. I should've tried it sooner. Would've saved me a lot of hasstle.

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

Similar Threads

  1. Replies: 2
    Last Post: 10-07-2019, 10:46 AM
  2. Data type mismatch - handling null values
    By shank in forum Reports
    Replies: 5
    Last Post: 05-14-2019, 08:29 AM
  3. Replies: 2
    Last Post: 04-17-2017, 01:40 PM
  4. Replies: 8
    Last Post: 09-12-2015, 11:28 AM
  5. Query on a Unbound form with Null Values
    By Kenny in forum Queries
    Replies: 2
    Last Post: 05-24-2012, 12:51 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