How to check whether the value in text field is Date type

  • Thread starter Thread starter Boon
  • Start date Start date
B

Boon

Hi,

I ahve a text box. How can I check if the value in the textbox is a date. I
want a user to only put in a date. I use the date selector (calendar). But
user can still type in text. I use Access 2007

Thanks,
Boon
 
Boon said:
Hi,

I ahve a text box. How can I check if the value in the textbox is a date.
I want a user to only put in a date. I use the date selector (calendar).
But user can still type in text. I use Access 2007


If you set the Format property of the text box to one of the date formats
(e.g., "Short Date"), the user will only be able to enter values that can be
converted to dates. Or, if this is a bound control, if the underlying field
is a Date/Time field, the user won't be able to enter any non-date value.
Null values are still okay, in these cases.

The text box must be unformatted and unbound, you can use the IsDate()
function to determine whether the value can be interpreted as a date:

If IsDate(Me.txtDateEntered) Then
' This is a date value
Else
' It's null or a non-date.
End If

Note that all of these approaches allow the user to enter something like
"January 1", because Access can interpret that as a date.
 
Back
Top