Insert currrent date into selected record field with button ?

B

+Bob+

I have a continuous form with the records from the table listed
sequentially (like a datasheet, but my form).

I would like to be able to click on the record selector to select a
record (or maybe multiple selections for the deluxe version) then
click on another button on the form to insert today's date into a
field in the selected record(s). I also need to be able to enter a
date manually into the field sometimes... but entering the current
date is the going to be done about 90% of the time.

I know how to get a button to run an event procedure and I can hack my
way around the vb code in general and use now() - but how to I hook
the selected record to do something like "selectedrecord.somefield =
now()" ?

I'm new at this, so a complete sample procedure would go a long way to
getting me where I need to go.



Thanks,
 
K

Ken Snell \(MVP\)

You can use the keyboard shortcut
Ctrl + ;
to enter today's date into a control on the form in the selected record. May
be a lot easier than coding a button to do the same thing.

Otherwise, in a continuous forms view setup, the selected record is
"accessed" by just referring to the field or control name in the data
recordset. The form will "know" it's the one in the selected record. So the
button's code for writing today's date into the control would be this (using
the button's click event):

Private Sub NameOfTheButton_Click()
Me.NameOfTheControl.Value = Date()
End Sub
 
B

+Bob+

Private Sub NameOfTheButton_Click()
Me.NameOfTheControl.Value = Date()
End Sub

In the above example, NameOfTheControl would be the "Control Source"
from the field on the form ? Should I need to qualify it as
table.field ?

What does the "Me" represent ?
 
D

Douglas J. Steele

NameOfTheControl would be the Name of the control. That may or may not be
the same as the ControlSource.

"Me" provides a way to refer to the specific instance of the class where the
code (in this case, the form) is executing. In other words, if your code is
running in form frmABC, using Me.NameOfTheControl is the same as using
Forms!frmABC!NameOfTheControl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top