Solved

"xxxxxx" is not a valid date and time

Posted on 2004-03-30
8
3,522 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
 
LVL 4

Expert Comment

by:SurferJoe
ID: 10718880
Calinutz,

Only 2 beers? what kinda programmer are you:)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

910 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

23 Experts available now in Live!

Get 1:1 Help Now