How can I make a date variable assigned empty like we do with strings by setting ""
Printable View
How can I make a date variable assigned empty like we do with strings by setting ""
Hi,
Use NULL to assing a blank in date field.
or alternatively -
in INSERT INTO statement do not include the date fields, it will automatically be blank.
Santulan
My problem is as below regarding dates
Dim StartDate as Date
StartDate = #10/01/1999#
...
...
...
Now I want to make the variable empty
I tried to issue null
StartDate = Null
'' Giving Error
Check out this
use vbNull
RK
In access if you update and set date = "" date gets blank.
or you try vbNull
Santulan
I realize I'm writing this 11 years after the initial query, but the advice given is erroneous, and so I'm adding this so others who see this page are not misled. vbNull is intended strictly for use with the VarType() function to test if a variable is Null, as follows:
If VarType(abc) = vbNull Then
You cannot use vbNull to set a variable to Null. Indeed, if you try it, like so:
abc = vbNull
then the variable will actually be assigned a value of 1 (or "1" if it's a string variable). So if you do that then obviously an IsNull() test would fail to work properly because the variable is not null.
My understanding is that for a code variable you can't actually assign a Null to it unless it's a Variant data type (unlike an Access table field, which you can assign as Null). So a string variable must be assigned as empty string and a numeric must be assigned zero (or whatever else you want to used to signify as "unassigned" in the logical context of your code), like so:
str = ""
num = 0
Why dig up long-dead posts?
Reply to Your Query - Solved
If you declare any variable as date format, it will the data like as "00:00:00".
So before execute your sql command , please verify the contents in the date varaible as follws
If isdate(Var_date) = True or Var_date <> "00:00:00" Then
Tablename!Fieldname = Var_Date
else
TableName!FieldName =Empty
End if
recordset.update
I tried the above method, it works with MsAccess and MSSQL too
Thank You
I just can't understand why someone would register on a site to replay to a question that was asked 14 years ago ???
Two negatives don't always result in a positive! :(