Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3623
  • Last Modified:

"xxxxxx" is not a valid date and time

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
vanmilp
Asked:
vanmilp
1 Solution
 
calinutzCommented:
try
Query1.Active:=true;
except
ShowMessage('error on date time format');
end;


Cheers
0
 
calinutzCommented:
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
 
Mohammed NasmanSoftware DeveloperCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Greg RowlandSoftware Designer, SysDBA, WebMaster OwnerCommented:
Calinutz,

Only 2 beers? what kinda programmer are you:)
0
 
kretzschmarCommented:
>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
 
vanmilpAuthor Commented:
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
 
Mohammed NasmanSoftware DeveloperCommented:
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
 
Mohammed NasmanSoftware DeveloperCommented:
vanmilp, why grade "B", :-(
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now