views:

792

answers:

5

I have two validation for date and time as below in text boxes:

00/00\ 00:00;0;0;_

It will take (dd/mm hh:mm) and works fine

But sometimes i put

34/34 56:78 it will take , But it shouldn't

Date sholdnot go beyond 31, month 12 time 24 and minute 59

Please help

A: 

validate the date using IsDate()

Public Function ValidateDate(input As String) As Boolean    

    ValidateDate = IsDate(input)

End Function

this returns a boolean value, True if the input is a valid date string, False if it isn't. The maximum values are

Day: 31

Month: 12

Hour: 23

Min: 59

Sec: 59

Russ Cam
Sorry i edited my question ; this is an input mask not validation
is that an input mask on the table field or on the textbox on the form? You will still need some form of validation on the form and can put this function in the On Exit event
Russ Cam
Thanks for response; i only need input mask no validation Is it possible to restrict this with input mask?
A: 

Input masks in Access cannot be restricted to ranges of values, like with a RegExp. Only way to do this is use some validation (which can be done on a keypress if you want to).

birger
A: 

Approach the problem differently. Give the user a calendar to pick from. You could use something like Allen Browne's Popup Calendar

Disable and lock the text field and you can guarantee that the format is correct.

CodeSlave
+1  A: 

I just encountered this problem with a Credit Card expiration date field yesterday. I'd stupidly changed 00/0000 as input mask to 00/00, and encountered the problem you're having. the issue is that if the second pair of digits is a valid date, it will be interpreted as a date and the current year will be supplied tacitly. Thus, if you enter:

  06/09

for Jun 2009, it will be stored as:

  06/09/2009

On the other hand, if you enter:

  06/34

it will be interpreted as

  06/01/1934

So far as I can see, the only way for you to do what you want is to use a 4-digit year.

David-W-Fenton
A: 

if you use the pop up calendar, how would you set it so they do NOT choose a day, just a month/year?

jack
Which popup calendar? The one in A2007 is very different from the one in previous versions, and both of them require display of month and date. It doesn't seem like a very good idea to display choices that are meaningless (i.e., pick a day when the day is not going to be recorded).
David-W-Fenton