Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a const for the default value of the Date variable type, a la vbNullString for the string type?

I have a column of dates. These will be incorporated into objects, one per row, along with other data in the row.

However, some of the cells in the date column are empty. As I test I create a date variable and set its value as the value of an empty cell. I msgbox'd the new value of the date and found it was "12:00 AM". Is there a constant built into VBA to represent this value, so I can do tests similar to:

If myDate = vbNullDate Then
like image 852
Swiftslide Avatar asked Jan 20 '26 21:01

Swiftslide


2 Answers

I run into this problem from time to time. I usually do the below:

dim d as date
if d = cdate(0) then msgbox "Default value" 
like image 180
racoon5 Avatar answered Jan 22 '26 13:01

racoon5


The default value for a local Date variable seems to be:

Saturday, December 30, 1899 12:00:00 AM

based on this procedure:

Sub testdate()

Dim d As Date

Debug.Print Format$(d, "Long Date") & " " & Format$(d, "Long Time")

End Sub

To check the default value for any variable type, simply declare a variable of that type, then print it's value.

Sub testint()

Dim d As Integer

Debug.Print d

End Sub
like image 45
JimmyPena Avatar answered Jan 22 '26 12:01

JimmyPena



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!