error handling

I have a form, in which a user enters data. One of the fields on the form is a date field. I want this to happen when a users clicks on "continue":

If the user entered an invalid date, for example the correct format is "12/12/2004". If he enters "12-12-2004" . Then I should highlight the text box for date.

Thanks,

Venkat
gbvreddyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ADSaundersCommented:
Hi gbvreddy,

Private Sub Continue_Button_Click()
  ' Validate date field here
  if not valid then
    Datefield.setfocus
    exit sub
  else
    ' do whatever needs to be done with a valid date
  end if
End Sub

Regards .. Alan
0
reginabCommented:
isValidDate will pass both of those, however you can put a date format in a registry key and then copare to that, or you can hard code it into your program though that sucks if you change your mind later on what you want to be accepted, if you use a key you can change it any time. then just focus back to text box when the form fails because of the date error.

like this
<body onload="document.forms['formName'].elements['elementName'].focus()">


where formNAme is the Name of the FORM :
<FORM name="formName" id="formName">

and elementName is the elementNAme :
<input type="text" name="elementName" id="elementName">

then pass the element name back from the validation code.
0
Erick37Commented:
You could test if the date is valid, then format it as you wish for the user:

Private Sub cmdContinue_Click()

    'validate Text1
    With Text1
    If IsDate(.Text) Then
        .Text = Format(.Text, "MM/DD/YYYY")
    Else
        MsgBox "Please enter a valid date"
        .SetFocus
        .SelStart = 0
        .SelLength = Len(Text1.Text)
    End If
    End With
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mlmccCommented:
How about using a calendar control like the DatePicker.  Ensures user can't enter an invalid date and ensures no confusion over proper format.

mlmcc
0
gbvreddyAuthor Commented:
Thanks a lot everyone !

Venkat
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.