Solved

"xxxxxx" is not a valid date and time

Posted on 2004-03-30
8
3,533 Views
Last Modified: 2007-11-27
I have a form with a few DBEdits on it, which are connected to a Date-Field (Access-database).
When I fill in a non-existing date,and try to leave the DBEdit, I get the standard message "xxxxxxxxxx is not a valid date and time". How can I get rid of this message, and replace it with my own message ?

0
Comment
Question by:vanmilp
8 Comments
 
LVL 11

Expert Comment

by:calinutz
ID: 10718344
try
Query1.Active:=true;
except
ShowMessage('error on date time format');
end;


Cheers
0
 
LVL 11

Expert Comment

by:calinutz
ID: 10718379
Sorry...
not paying too much attention (after 2 beers). The question is ... your DBEdits are generated from a table component? Or a Query returns the field? You should try Table if you are using a Query. Anyways you can put your "try" in the onExit Event of the DBEdit....
Cheers
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 10718524
Hello

  You can catch that on the OnSetText event of the field, to use this event you need to add the fields by double click on the table components, then right click on the field editor, then choose add field, choose the field that you want to check and write this code on the OnSetTextEvent

function IsDate(s : string) : Boolean;
begin
  try
    StrToDate(S);
    Result := True;
  except
    Result := False;
  end;
end;

procedure TForm1.Table1Event_DateSetText(Sender: TField;
  const Text: String);
begin
  if not IsDate(DbEdit4.Text) then
    MessageDlg('Enter Valid Date',mtError,[mbOk],0);
end;

IsDate a function that I use to check if a string is a valid date

Regards,
Mohammed
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 4

Expert Comment

by:Greg Rowland
ID: 10718880
Calinutz,

Only 2 beers? what kinda programmer are you:)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10721136
>Only 2 beers? what kinda programmer are you:)
i drink no beer, because i don't like the taste,
what a programmer am i?

meikl ;-))
0
 

Author Comment

by:vanmilp
ID: 10721597
Calinutz, your solution doesn't work (I already tried that, forgot to mention it), besides that it doesn't respond to each field being edited, only to a record.

Mohammed, your solution seems to work, at least I can create the error-message for wrong input.
However, when I type in a correct date, the entered text disappears from the DBEdit ???

0
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 125 total points
ID: 10721637
vanmilp, add this line to the check

  else
    Sender.Value := Text;

it will look like this

procedure TForm1.Table1Event_DateSetText(Sender: TField;
  const Text: String);
begin
  if not IsDate(DbEdit4.Text) then
    MessageDlg('Enter Valid Date',mtError,[mbOk],0)
  else
    Sender.Value := Text;
end;

Regards,
Mohammed
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 10730642
vanmilp, why grade "B", :-(
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

828 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