Dates

H

Hissha

I have created forms for each employee to track their workload. If an
employee does 10 activities (10 new records) on the same date, how can I get
the date from record 1 to remain in the date field until the employee needs
to change it for record 11 and then have the date remain in the date field
until the employee has to change it again?
 
F

fredg

I have created forms for each employee to track their workload. If an
employee does 10 activities (10 new records) on the same date, how can I get
the date from record 1 to remain in the date field until the employee needs
to change it for record 11 and then have the date remain in the date field
until the employee has to change it again?

Code the DateControl's AfterUpdate event:

Me.DateField.DefaultValue = "#" & [DateField] & "#"

The default value will remain until a different date is entered by the
user.
 
K

Ken Sheridan

Fred:

If I may suggest one amendment to your reply; use this instead:

Me.DateField.DefaultValue = """" & [DateField] & """"

The DefaultValue property is a string expression regardless of the data
type. Most of the time it doesn't matter, but with dates its important due
to the variations internationally in date formatting. Your code would fail
most of the time on a system using European short date format dd/mm/yyyy as
date literals must always use the US format mm/dd/yyyy or another
internationally unambiguous format; the value in the current record would
transpose the day and month on a European system. If this resulted in a
valid, but incorrect, date in European format the incorrect date would be
used as the default value; if it resulted in an invalid European format date
Access detects this and switches the days and month round again, so the value
would be correct.

By wrapping the value in literal quotes as above this internationalizes it
and it will work with any system date format.

Similar considerations have to be employed in other contexts, e.g. when
taking the value from a control or variable as the criterion for a DLookup
function call it should be formatted in US date format to be sure of a
correct result whatever the system date format:

DLookup("MyID", "MyTable", "MyDate = #" & Format(txtDate,"mm/dd/yyyy") & "#")

Ken Sheridan
Stafford, England

fredg said:
I have created forms for each employee to track their workload. If an
employee does 10 activities (10 new records) on the same date, how can I get
the date from record 1 to remain in the date field until the employee needs
to change it for record 11 and then have the date remain in the date field
until the employee has to change it again?

Code the DateControl's AfterUpdate event:

Me.DateField.DefaultValue = "#" & [DateField] & "#"

The default value will remain until a different date is entered by the
user.
 
Top