Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Date problem

Posted on 2000-05-14
7
Medium Priority
?
169 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Suggested Courses

715 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