Solved

Date problem

Posted on 2000-05-14
7
164 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
Industry Leaders: 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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

679 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