Topic: Dateadd problems

Looking how to create a script where the expiration datepicker automatically shows +30 days once you select the inspection datepicker on the form.
If possible the expiration can not be edited. Basically "Read Only". But, if this can't work thats ok.

table tCertificate
Inspection DATETIME
Expiration DATETIME

I'm still new with this program and sql in general. I've done sveral ways but none seem to work.

Re: Dateadd problems

Hi Chrisyoco,
You have a couple of options - one without a script and one with a script.
1.  Without a script.
Use a calculated field - have a look in the 'datatables'section at the 'cfexipirydate' field to see the syntax.  There is no possibility for the user to edit the expiry date because it is calculated rather than input and stored.
2.  With a script.
The script is triggered whenever the inspection date is changed.  In this example, I have placed the expiry date on Form2 (so you can see how it changes as the inspection date is changed) but I have set the 'enabled' property of the expiry date to 'false' so that the user can't amend it.
Hope either of these two approaches helps and if something isn't clear, just leave a message in the Forum and someone will get back to you.
Regards,
Derek.

Post's attachments

Attachment icon chrisyoco.zip 674.36 kb, 375 downloads since 2018-09-08 

Re: Dateadd problems

Script

procedure Form1_dtInspection_OnChange (Sender: TObject);
begin
    Form1.dtExpiration.DateTime :=  Form1.dtInspection.DateTime + 30;
end;

Set property Enabled = False for the component dtExpiration, so can not be edited.

Dmitry.

Re: Dateadd problems

Thank you very much. These worked really well.