Solved

Date problem

Posted on 2000-05-14
7
161 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now