View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
onedaywhen onedaywhen is offline
external usenet poster
 
Posts: 459
Default Null date in VBA variable

How do you return a null date in VBA? The value zero in Excel VBA is a
valid date (i.e. 30-Dec-1899), even negative numbers are valid (e.g.
-ve 999 is 05-Apr-1897). The usual solution is to use a known date to
signify a null value, preferably one which is implausible in the
context of your app. For example, in a recent project here we used
Newton's birthday to signify a null, however I wouldn't recommend this
because of a double ambiguity (01/04 or 04/01 depending on your
locality or 25/12 depending on calendar system used!)

Harald Staff wrote
I'm not sure how/if you can set a database field to be Null either.


Sure can. NULL or NOT NULL is an essential definition of a SQL-92
column:

CREATE TABLE MyTable
(
ID INTEGER NOT NULL PRIMARY KEY,
LastName VARCHAR(35) NOT NULL,
FirstName VARCHAR(35) NOT NULL,
MiddleName VARCHAR(35) NULL
);

How to set a column's value to null? Definite as NULL and don't put
anything in it! However, even with databases it's recommend to
disallow nulls and specify a default value to use if nothing is put in
the column e.g.

MiddleName VARCHAR(35) NOT NULL DEFAULT '{{NK}}'

--

"Harald Staff" wrote in message ...
Hi Dennis

As soon as you define a variable as a date, it gets the default value zero.
Null is "unknown", while zero is day zero. VBA doesn't really operate with
Null in the database sense of the word.

I'm not sure how/if you can set a database field to be Null either. What's
this for ?

HTH. Best wishes Harald

"Den" skrev i melding
...
Given a VBA variable of type date, how can you set the variable to a null
value.

I tried mydate = Null. But VBA does not like that.

Is there someway to set it to null. It is a variable that will be passed
to an SQL database.

Thanks
Dennis