Solved

Date problem

Posted on 2000-05-14
7
163 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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 15 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

825 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