Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Date problem

Posted on 2000-05-14
7
Medium Priority
?
171 Views
Last Modified: 2010-05-02
my app. closed when a user type a wrong DATE in the form - i used MASK Edit control , what is a problem ?
0
Comment
Question by:ahmedali
7 Comments
 

Author Comment

by:ahmedali
ID: 2809507
Adjusted points from 5 to 15
0
 
LVL 12

Expert Comment

by:pjknibbs
ID: 2809598
What error did you get?
0
 
LVL 2

Expert Comment

by:BobbyOwens
ID: 2809620
It may be a problem in that the format of the date was correct, but the date itself isn't.

e.g. 31/02/2000

Your best bet is to use the CDate function in the validate event.

eg:
dim dtmDate as date

on error resume next
dtmDate = cdate(mskDate.Text)
if err <> 0 then
  cancel = true
end if
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:lochiano
ID: 2810887
Another solution is to use the DTPicker control.  The adventage of this is that the value returned is a data.  You can set a Min and a Max date for a value range.

0
 
LVL 4

Expert Comment

by:Jeremy_D
ID: 2811070
The problem is that you didn't have an error handler. Unhandled errors cause the application to close down.
In the sub you assign the returned value from the control (probaly some Change-event) to a variable, include an errorhandler:

Private Sub MyControl_Change(...)
    On Error Goto ErrHandler

    'Your code goes here

    Exit Sub

ErrHandler:
    MsgBox "You typed in an invalid date, try again."
    Resume
End Sub


0
 

Accepted Solution

by:
greeno earned 60 total points
ID: 2812439
To solve your problem I would change the mask edit control to a normal edit control and then use the controls  Validate event. The Validate event will stop the control from losing focus if invalid data is entered.

Change the maskedit to a normal textbox called txtDate

Implement the Validate event.

Private Sub txtDateValidate(Cancel As Boolean)
  If Not IsDate(txtDate) or txtDate = "" Then
    MsgBox "Not a valid date."
    Cancel = True  
  Else If DateDiff("d", txtDate, Now) < 0 Then
    MsgBox "Date must be before today"
    Cancel = True
  End If
End Sub
0
 

Author Comment

by:ahmedali
ID: 2816005
Hello   Thank you for your comment ,i have accept it as an answer and i give you the points and Excellent grade .
note:
there is no seperator .
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

927 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