Results 1 to 2 of 2

Thread: Date validation

  1. #1
    Join Date
    May 2002
    Posts
    19

    Unanswered: Date validation

    I have two unbound fields on a form. The users inputs a Start date in the first field and an end date in the latter. I am using the DateValue to determine that the Start date is prior to the End date. However, what code can I use to determine if both fields have valid dates. I have found that if the users mistakenly (or otherwise) types in an invalid date, my program crashes at my DATEVALUE function because it is trying to process an invalid date. Any help is appreciated.

    Thanks

  2. #2
    Join Date
    May 2002
    Location
    Atlanta, GA
    Posts
    117
    Hello,

    If you want to make sure that users are inserting proper dates I would create a form with two fields, Start Date and End Date, change the format of your fields to Short Date and then add an input mask like 99/99/0000;0;_ so they are forced to enter a proper date. To verify the dates entered you could use code like this:

    If IsNull(Me.StartDate) Then
    Msgbox "Please enter a start date."
    Me.StartDate.SetFocus
    Exit Sub
    End If
    If IsNull(Me.EndDate) Then
    Msgbox "Please enter an end date."
    Me.EndDate.SetFocus
    Exit Sub
    End If
    If Me.StartDate >= Me.EndDate Then
    Msgbox "The Start Date cannot be equal to or greater " & _
    "than the end date."
    Me.StartDate.SetFocus
    Exit Sub
    End if

    You may have to change the field names to suit your form but that should get you started.

    Hope this helps, Kal

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •