Default Null Dates to Zero Value Number

Posted on 2009-12-30
Last Modified: 2012-05-08
I'm using MSQuery in Excel to query an Access table.  I HAVE to use MSQuery.  I'm running into a problem since MSQuery cannot handle null dates with something like an NZ function in Access.  So I think I'm going to have to alter the date fields in my Access table so MSQuery can query it.  Currently the Date/Time field in the Access table can hold nulls.  How do I set the null date/time values to the equivalent of 0 in the Access table?  Is there such a value?  I ask because I remember querying a table a while ago that when the results exported into Excel, the actual value was the date 1/0/1900 ----which equates to 0 in Excel.  I will be outputting the query results in Excel so I need something that won't equate to a "real" date that can confuse the query results.  Also, what is the best way to set the null date/times to a 0 equivalent date, through a NZ() update statement or set it at the property level of the table itself?  Thanks.
Question by:error_prone
    LVL 28

    Expert Comment

    Might be easier to create a query in Access to query the table and use the NZ function to set the nulls to 0.  Then use MSQuery to query the query.  That's a lot of queries in one sentence.

    OM Gang
    LVL 77

    Accepted Solution

    a datetime value of 0 would equate to 31/12/1899 and that is what both Access and Excel will display in a  field/cell formatted as date.  I think you would have to do explicit tests to prevent such a display in Excel.
    LVL 11

    Expert Comment

    Well for course there is no zero date, and the numeric value 0 equates to 12/31/1899 as Peter said.  I think the simplest thing would be for you to arrange for nulls to be replaced with some arbitrary standard date value, say 1/1/2500, and then inform the users of the output that 1/1/2500 indicates no date is available.

    Author Comment

    I'm running an append query to populate this Access table which has the null date/time fields.  I deleted the table and set the default value of the field to #12/31/1899# and re-appended the table.  But that didn't work, (not sure why).  I'm running an update statement right now on the field....

    Author Comment

    Ok, updating the field to 12/31/1899 worked.  

    Author Closing Comment

    I'm going to have to play around with Excel to get that value to conditionally format to white font, (ie hide the value).  It's not working the same as the value 1/0/1900 for some reason.  However, if I put the equal sign in front of 12/31/1899 it changes to 1/0/1900 in Excel.  Odd...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
    How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
    This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now