Solved

"xxxxxx" is not a valid date and time

Posted on 2004-03-30
8
3,507 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
Comment Utility
try
Query1.Active:=true;
except
ShowMessage('error on date time format');
end;


Cheers
0
 
LVL 11

Expert Comment

by:calinutz
Comment Utility
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:mnasman
Comment Utility
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
Comment Utility
Calinutz,

Only 2 beers? what kinda programmer are you:)
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
>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
Comment Utility
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:
mnasman earned 125 total points
Comment Utility
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:mnasman
Comment Utility
vanmilp, why grade "B", :-(
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

12 Experts available now in Live!

Get 1:1 Help Now