Create Auto Date in Subform

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

I use a subform for tracking notes of phone calls that were placed.

The subform contains a few fields.. for instance, DATE, SUBJECT, NOTES, etc.

When I open the subform for a specific customer, I don't want to enter
"Today's Date" into the Date field.

What's the best way to have the system enter the current date (maybe even
time in another field) once I place the cursor into the Subject field.

I need to make sure that the automatically entered date will be static
(instead of always showing the current system date).

Does anyone know how to do that?
 
1. Open the subform in design view.

2. Right-click the date field, and choose Properties.

3. Set the Default Value property to:
=Date()

Access will drop today's date into the field whenever you create a new
record.

If you wanted the date and time, use:
=Now()

On a side note, "Date" is a reserved word in VBA, so avoid using that as a
field name. (Can be ambiguous in some contexts.)
 
Thanks, Allen..

that works great.

Tom


Allen Browne said:
1. Open the subform in design view.

2. Right-click the date field, and choose Properties.

3. Set the Default Value property to:
=Date()

Access will drop today's date into the field whenever you create a new
record.

If you wanted the date and time, use:
=Now()

On a side note, "Date" is a reserved word in VBA, so avoid using that as a
field name. (Can be ambiguous in some contexts.)
 
Along these same lines: I have a form that is used for both adding new
records and editting existing. There is a field for the date the record was
last updated. The data entry person has been changing it when she edits a
record but forgets. So, I need the field to remain as is if the record is
merely viewed, but to update to today's date if any other field is changed.
Will these instructions work for this scenario?

Thanks,
Cathy
 
Assuming your date/time field is called "UpdatedOn", use the BeforeUpdate
event of the form to assign the current date and time.

The Event Procedure would be:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.[UpdatedOn] = Now()
End Sub

If you want just the date (not the time as well), replace "Now()" with
"Date()".
 
Cool! Can't believe it's so simple ... when you know.

Thanks much.
Cathy
Allen Browne said:
Assuming your date/time field is called "UpdatedOn", use the BeforeUpdate
event of the form to assign the current date and time.

The Event Procedure would be:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.[UpdatedOn] = Now()
End Sub

If you want just the date (not the time as well), replace "Now()" with
"Date()".

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Cathy C said:
Along these same lines: I have a form that is used for both adding new
records and editting existing. There is a field for the date the record was
last updated. The data entry person has been changing it when she edits a
record but forgets. So, I need the field to remain as is if the record is
merely viewed, but to update to today's date if any other field is changed.
Will these instructions work for this scenario?

Thanks,
Cathy
 
Back
Top