NOT NULL Values for Dates

The Archn00b

Registered User.
Local time
Yesterday, 22:39
Joined
Jun 26, 2013
Messages
76
Hi again

I have a text box with a date picker in a form. I need to create a piece of conditional logic in Visual Basic that is activated when the value in the form is not null. I can't so this in the same way as I would with a string which would be:

Code:
If Field <> "" Then
Statement
End If

Does any one know the equivalent for the Date datatype in Visual Basic?

Thanks for reading!
 
I'd probably use IsDate().
 
I'd probably use IsDate().

Ah OK...

IsDate returns True if Expression is of the Date Data Type or can be converted to Date; otherwise, it returns False.
The Date data type holds both a date value and a time value. IsDate returns True if Expression represents a valid date, a valid time, or a valid date and time.

From http://msdn.microsoft.com/en-us/library/office/gg264241.aspx

If I was to change the default value to "null" in the property sheet, this wouldn't be seen as a date value and would represent the condition of the text box being blank? I'll try it.
 
Null should not be seen as a date, no.
 
Doesn't work I'm afraid.

"Invalid Use of Null"

The only think i can think of is to use the default text box date value which is 01/01/0001 which would be very unlikely to be queried anyway. I'll try that.
 
How did you use it exactly?

?isdate(null)
False
 
It refuses to even let me enter that date. It just changes it automatically to 01/01/2001, which is no good. Is there any way I can reference "default" as a value without putting in the actual default value in this case?
 
How did you use it exactly?

?isdate(null)
False

Code:
Dim DateValue As Date
DateValue = DateBox.Value
Dim DateCheck As Boolean
DateCheck = IsDate(DateValue)
Dim DateBox_Parameter As String
If DateCheck = "True"  Then
STATEMENT
Else
STATEMENT
End If
 
The DateValue variable can't handle a Null, which is where your error comes from. It would have to be declared as Variant to take a Null. Here's code out of a db I have open that works fine with Nulls:

Code:
  If Not IsDate(Me.txtReqDate) Or Not IsDate(Me.txtReqTime) Then
    MsgBox "Must fill out requested date and time"
    Me.txtReqDate.SetFocus
    Exit Function
  End If
 
By the way, since there's a DateValue function, I wouldn't use that as a variable or object name.
 

Users who are viewing this thread

Back
Top Bottom