Auto Insert Date?

  • Thread starter Thread starter Dunner
  • Start date Start date
D

Dunner

Hi,

Is there a way to automatically set a field with the
current date when a user ticks yes in another yes/no
field?

It needs to be a global sort of implementation as the
field can be edited from several different forms.

Thanks for the help

Dunner
 
Using a macro, you could do this *if* the name of the field (better, an
invisible textbox that is bound to the field) is the same in all the forms.
Macros allow you to drop off the form name if the macro is being called from
a form and you want to use a control or field that is in that form.

MacroName: macSetTodayDate

Condition: [NameOfCheckBoxControl] = True
Action: SetValue
Item: [NameOfTheDateControl]
Expression: Date()

Condition: [NameOfCheckBoxControl] = False
Action: SetValue
Item: [NameOfTheDateControl]
Expression: Null

The above macro should be run from the After Update property (when the
AfterUpdate event occurs) of the checkbox control on the form. Note that
each form must use the same name for the checkbox control too. This macro
will put today's date in the textbox if the checkbox is checked, and will
put Null in the textbox if the checkbox is unchecked.

A shorter way to do this same macro would be this:

MacroName: macSetTodayDate

Action: SetValue
Item: [NameOfTheDateControl]
Expression: IIf([NameOfCheckBoxControl], Date(), Null)
 
Hi Ken,

Would this update the field with today's date each time
the form is updated (i.e. if I update the checkbox today
the field will read 24/08 but if I update a different
field on the same record say tomorrow the date will be
updated to 25/08)?

The reason I ask is that I need it to be static once the
box is checked so that the date can be compared with
today's date and then various procedures executed when it
reaches a certain age.


Thanks for your help

Dunner
 
The macro that I posted will only update the date value if you click the
checkbox itself. Changing other controls on the form will not affect the
date value.

--

Ken Snell
<MS ACCESS MVP>

Dunner said:
Hi Ken,

Would this update the field with today's date each time
the form is updated (i.e. if I update the checkbox today
the field will read 24/08 but if I update a different
field on the same record say tomorrow the date will be
updated to 25/08)?

The reason I ask is that I need it to be static once the
box is checked so that the date can be compared with
today's date and then various procedures executed when it
reaches a certain age.


Thanks for your help

Dunner

-----Original Message-----
Using a macro, you could do this *if* the name of the field (better, an
invisible textbox that is bound to the field) is the same in all the forms.
Macros allow you to drop off the form name if the macro is being called from
a form and you want to use a control or field that is in that form.

MacroName: macSetTodayDate

Condition: [NameOfCheckBoxControl] = True
Action: SetValue
Item: [NameOfTheDateControl]
Expression: Date()

Condition: [NameOfCheckBoxControl] = False
Action: SetValue
Item: [NameOfTheDateControl]
Expression: Null

The above macro should be run from the After Update property (when the
AfterUpdate event occurs) of the checkbox control on the form. Note that
each form must use the same name for the checkbox control too. This macro
will put today's date in the textbox if the checkbox is checked, and will
put Null in the textbox if the checkbox is unchecked.

A shorter way to do this same macro would be this:

MacroName: macSetTodayDate

Action: SetValue
Item: [NameOfTheDateControl]
Expression: IIf([NameOfCheckBoxControl], Date(), Null)
 
Back
Top