Correct test for an empty date?

  • Thread starter Thread starter LAS
  • Start date Start date
L

LAS

I have a global variable that contains the last date the user entered in any
option. It should be initialized to the current date. In various forms I
need to see if it is empty so I know whether or not to assign Date(). It
looks like I need to test to see if it equals #12/4/1899#. I can do that
but it feels klugey. Is there a better way?

TIA
LAS
 
I have a global variable that contains the last date the user entered in any
option. It should be initialized to the current date. In various forms I
need to see if it is empty so I know whether or not to assign Date(). It
looks like I need to test to see if it equals #12/4/1899#. I can do that
but it feels klugey. Is there a better way?

TIA
LAS

How is it "initialized"? Unless it has a Default Value, it should be NULL (not
equal to any date). The zero point of date/time fields is #12/30/1899# - are
you doing some kind of calculation to subtract 25 days from the entered date?

Please post your code.
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 
I was just about to post an "oops." The value it has at the beginning is
12:00:00 AM. (I should have named the variable gdtSession_Date...)

The only place it gets established before a form is opened is in this
declaraition. When any form is opened, it has the value 12:00:00 AM.

Public gsSession_Date As Date

I used UcoraFindandReplace to be sure that it wasn't getting assigned to
anything anywhere.
 
I was just about to post an "oops." The value it has at the beginning is
12:00:00 AM. (I should have named the variable gdtSession_Date...)

The only place it gets established before a form is opened is in this
declaraition. When any form is opened, it has the value 12:00:00 AM.

Public gsSession_Date As Date

I used UcoraFindandReplace to be sure that it wasn't getting assigned to
anything anywhere.

Sorry... it's a VBA variable, not a table field! My answer applied to the
latter.

If you use As Date in the Dim, then the variable must indeed have a value;
it's defaulting to 0.0, which is equivalent to #12/30/1899 00:00:00# and will
indeed be displayed as 12:00:00 AM.

You can test for it being uninitialized by comparing it to #12/30/1899# or to
#12:00:00 AM# or to 0, all of which are just different ways of depicting the
same thing... but it can't be NULL, as a table field can.
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 
I have a global variable that contains the last date the user
entered in any option. It should be initialized to the current
date. In various forms I need to see if it is empty so I know
whether or not to assign Date(). It looks like I need to test to
see if it equals #12/4/1899#. I can do that but it feels klugey.
Is there a better way?

Don't use globals.
 
Back
Top