Button on form to enter date and time?

  • Thread starter Thread starter Newbie1
  • Start date Start date
N

Newbie1

Hello all

Please excuse my ignorance (I have just started to use Access) I have only
created one database!

The last field of the form is "Work completed - date & time" I would like to
automate this entry by clicking on a button - Is it possible? If so could
someone point me to some sample code so I can learn more.

Thanks in advance

Newbie1
 
Automate it as in inserting the current date and time into the control
(fields are in tables; controls are on forms and reports)?

Use the OnClick event of the button:

Private Sub CmdButtonName_Click()
Me.WorkCompletedControlName.Value = Now()
End Sub

To set this code up, open the form in design view, click on the command
button, click on the Properties icon on toolbar, click on Events tab, click
in box next to "On Click", click on "three-dots" button at far right of box,
and select Code Builder (if asked). Visual Basic Editor (VBE) will open and
you'll see the first and third lines from above (with a blank line between
them), except that CmdButtonName will be replaced by the real name of the
command button. Type the second line into the blank line, but replace
WorkCompletedControlName with the real name of the control that is to get
this date and time value. Close VBE. Save form. Close form.

You're now ready to use it.
 
Back
Top