Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

error handling

Posted on 2004-11-15
5
Medium Priority
?
149 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:gbvreddy
5 Comments
 
LVL 10

Expert Comment

by:ADSaunders
ID: 12584908
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
 
LVL 4

Expert Comment

by:reginab
ID: 12584935
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
 
LVL 32

Accepted Solution

by:
Erick37 earned 2000 total points
ID: 12584996
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
 
LVL 101

Expert Comment

by:mlmcc
ID: 12586294
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
 

Author Comment

by:gbvreddy
ID: 12606454
Thanks a lot everyone !

Venkat
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question