Testing a Date formatted text box

  • Thread starter Thread starter J.C.
  • Start date Start date
J

J.C.

Here's one that eludes me.

I have a text box formatted as a Date control.

If nothing has been entered in the text box, it returns
Null.

If I programatically store a valid date in the text box,
and then clear the text box, it doesn't return Null, it
doesn't test to contain nothing (""), or a space " ".
Using the Intermediate window after my code stops at a
breakpoint, I can test the text box with a...
?Forms!FormName.DateTextBox
which returns Null.

I just need to test the text box progrmatically to insure
that there is a valid date in the control.

jc
 
Have you tried using the IsNull function on it?

If IsNull(Forms!FormName.DateTextBox.Value) Then
'the value of the textbox is null.
Else
'the value of the textbox is NOT null.
End If

If you are attempting to see if the value is a null value, if you try using
either of the following, it will not work as you would have expected:

If Forms!FormName.DateTextBox.Value = Null Then
Else
End If

Note, in the above condition, it will always branch out to the "Else"
statement and in the below condition, it will never interact with the Case
Null branch

Select Case Forms!FormName.DateTextBox.Value
Case Null
Case Else
End Select

The help file, "If...Then...Else Statement" also points this out within the
condition part explanation. The help file, "IsNull Function" does explain a
little further as to why it is treated as being False.
 
The IsDate()function seems to work consistently. I don't
find an equivalent function or Time - is there one?

jc
 
Not to my knowledge. If something is a date it automatically is a time.

MyDate = #11/13/2003#
FormatDateTime(MyDate , vbLongTime)

This will return 12:00:00 AM.
 
What do you mean sometimes it does and sometimes it doesn't? Since you
already have your textbox formatted as some sort of date format. In my
experience, I found that if you attempt to put in anything but a valid date
(even when it's not necessarily required), it will error out. If it's not a
required field, it would allow you to leave it blank.

Now, since I don't like how Access returns the errors from a user stand
point of view with it's generic error messages, I leave the format property
blank and have the textbox treated as a String Data Type, which then I run
my own validation checks on it both during the time of entry and after the
entry has been completed. Since I have issues with how Access Events works
for users, I have also created my own validation events, though this means
my forms and controls has to be unbound for them to work, but at least, by
using the work around that I have created, it allows for me to setup command
buttons that works just as how you would expect them to work like when
backing out of a form. I know it's just as easy to press the "Esc" key for
that, but I literally have some users that don't seem to pick up that
concept.
 
Back
Top