Link to home
Start Free TrialLog in
Avatar of yasanthax
yasanthaxFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Date Validation and accepting null values on Access Forms

Hi

I have an issue with some code behind a form, which previously worked but seem to break now.  The 3 dates on the form are defaulted and users can also manually edit it too in the field directly.  The 3 dated validate each other and the recording date has to be between the time started and time signed.

(1) Seems to be a problem with with dates manually entered through the input mask for DD/MM/YYYY HH:MM  ie 99\99\9999/99:99:0...  The criteria berow fails as macro cannot recognise a date format.

(2)  If I insert a CDate() for each field return, there will be a problem dealing with Null Values which should be accepted

Is there a better way of running these validations and also ignoring null values?

'If Me.txtTimeRecorded <> "" Then
'    If Me.txtTimeRecorded < Me.txtTimeStarted Then
'            MsgBox ("The Recorded Time can not be before the Start Time")
'            blnexit = True
'    End If
'    If Me.txtTimeRecorded > Me.txtTimeSigned Then
'            MsgBox ("The Recorded Time can not be after the Time Signed")
'            blnexit = True
'    End If
'End If
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yasanthax

ASKER

Thanks.  I did not know about this function and seems to fix it.
You are welcome!

/gustav