Today's Date for a Form Field

kaybeekaybee Member Posts: 49
The form is associated to a table with a field of type date. All I want it to do is to automatically populate the field with today's date.

So I just assign the "InitValue" in the table properties to "t", but this obviously does not work when ever the user creates a new record.

Comments

  • souravbsouravb Member Posts: 135
    Hi,
    When the user enters a new record on OnValidate of the field add:

    Datevar := TODAY
    It will be automatically populated with today's date.
  • DenSterDenSter Member Posts: 8,305
    No that's not the right place. If you enter tomorrow's date in that field, it would be a bit annoying when the system changes it to today's date. Plus, it would only do that if you actually enter something in that field, and the question was to enter the date automatically when a record is inserted.

    So...

    You definately want to program it on the table level, unless this is behaviour you want on this one form only. The trigger you're looking for is the OnInsert trigger. All you need to do is add a line:
    "Date Field" := TODAY;
    
    It won't be populated right when you hit F3, but as soon as the record is written to the database, you'll see it. Most of the time, this will be enough, because the record in master tables should be inserted when you enter the primary key anyway.
  • SunsetSunset Member Posts: 201
    And in case you need it straight away, you need to code it on every form that will make new records.
    On those forms I would suggest putting the code in "Form - OnNewRecord"
    Don't just take my word for it, test it yourself
Sign In or Register to comment.