Results 1 to 8 of 8
  1. #1
    Gary Childress is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Posts
    34

    Null Values in Date Fields Are Driving Me Insane

    I have a form called "Switchboard". On the Form called "Switchboard" is a combo box field called "FilterByAppointmentDates" that draws from a query called "AppointmentDates". The query "AppointmentDates" draws dates from a field in the table "MainDataTable". Using the "Group by" function I have excluded duplicate dates so that the query "AppointmentDates" only shows one instance of each date where there are duplicates.

    When I select a date on the form "Switchboard" I click the button "GetData" and it pulls all the records from the field "AppointmentDate" in the table "MainDataTable" with that date and brings them up in a query called "MainDataTableQuery". The query "MainDataTableQuery" is the record source for my form called "MainDataForm". Unfortunately I can't seem to get it to work when I have date fields with null values. It seems to confuse Access to no end to have null values. I have the same problem with other fields too so with the other fields I eliminate null values by creating a default value in the field. However, I don't want a default value in a date field. I want the field empty or else to have characters that are clear and easy to spot to indicate that the field has not been filled out. I tried putting the date "1/1/1999" as a default value. It's not an ideal state of affairs, however, when the default value is "1/1/1999" and I use the date picker to enter the real date, I have to scroll from 1999 to 2022 to enter the correct date.



    Is there a way to get this to work sensibly?

    I've been using the expression:
    Code:
    Like [FORMS]![SWITCHBOARD].[FilterByAppointmentDates] & "*"
    in the query design view in order to filter by date.

    I tried using
    Code:
    Like [FORMS]![SWITCHBOARD].[FilterByAppointmentDates] & "*" And Is Not Null
    , however, that seems to cause the query to return every date in that field in the table that is not null, defeating the purpose of having a date query.

    I'm stubbed.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Use the NZ() function to replace Null with whatever you like.

    However as the date field has no value, it will never be valid for your search for a certain date or date range?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Gary Childress is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Posts
    34
    Thanks for the quick reply. Would you be able to include an example of how the NZ formula could be used as a work around? Thanks!

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Nz function


    Sample usage: To give a future date #3/28/2022# ===28th of March

    SELECT
    EmployeeDaysLate.EmployeeId
    , Nz([DateLate],#3/28/2022#)
    FROM EmployeeDaysLate;

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Use a specific alias field name or Access will assign generic Expr1.

    I set up date textbox with InputMask to facility typing in date instead of relying on date picker - don't like the bugger.

    I try to build data entry forms to minimize mousing and allow all typed input.
    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.

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    I hate input masks, as you generally do not start at the beginning of a control if you click into it.

    Not just Access either, other programs have the same proble I have noticed.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Yes, so it is a balancing act between pet peeves and what is best for situation. Data entry that needs fast and efficient typed input is best without throwing in the oddball moused input. Start with first control on form and tab through and type. Never lift hands from keyboard. If user makes mistake and has to click back (unless they learn about Shift + Tab), that's on them. I even set up buttons with Alt+ shortcut keys so again, don't have to leave keyboard.
    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.

  8. #8
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    think you don't know what a date field actually is - it is a number. Today is 44634 - the number of days since 31/12/1899. Ao

    so something like
    Like [FORMS]![SWITCHBOARD].[FilterByAppointmentDates] & "*"
    is not going to work as you expect.

    now think about the logic of what this statement is actually saying

    Like [FORMS]![SWITCHBOARD].[FilterByAppointmentDates] & "*" And Is Not Null
    , however, that seems to cause the query to return every date in that field in the table that is not null, defeating the purpose of having a date query.


    leaving aside the issue mentioned above, your criteria is saying

    'return every record where mydate field is not null'

    with only a description of your issue and no example data and the outcome required, I think what you need as a criteria is

    =
    [FORMS]![SWITCHBOARD].[FilterByAppointmentDates] OR [FORMS]![SWITCHBOARD].[FilterByAppointmentDates] Is Null

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

Similar Threads

  1. Replies: 9
    Last Post: 04-09-2018, 10:41 AM
  2. Am I doing it wrong? Null Values & Date()
    By the problem in forum Queries
    Replies: 3
    Last Post: 07-25-2012, 01:34 PM
  3. Finding the Max Date and Null Values if Null
    By SpdRacerX in forum Queries
    Replies: 1
    Last Post: 02-03-2012, 06:29 AM
  4. Hide Fields With Null Values
    By jay in forum Reports
    Replies: 6
    Last Post: 09-22-2011, 07:23 AM
  5. Pls help... driving me insane!
    By Maverick1501 in forum Reports
    Replies: 1
    Last Post: 03-31-2010, 06:26 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