Paste current date and time into field

  • Thread starter Thread starter Fester
  • Start date Start date
F

Fester

I have what I think is probably a simple thing to do, but I can't
figure out how.

I want to have a button that paste's the current date and time at the
cursor in any field. Is this possible or do I need to utilize API's
and such to do this?
 
Hi

Create a textbox on your form (call it txtMyTimeAndDate)
Create a button on your form (Call it butSetDateTime)

On the OnClick event of the button put this

Private Sub butSetDateTime_Click()
Me.txtMyTimeAndDate = Now()
End Sub

To make it better for users to understand you could
set the format of the Text Boxto

dd / mm / yyyy hh:nn am/pm

Good luck

--
Wayne
Manchester, England.
 
Fester said:
I have what I think is probably a simple thing to do, but I can't
figure out how.

I want to have a button that paste's the current date and time at the
cursor in any field. Is this possible or do I need to utilize API's
and such to do this?
 
OK, I have the text box with the correctly formated data in it, how do
I get it to paste into the text field that I'm currently in? Is there
a way to programmatically CTRL-V to paste into the current field?

Actually, you'd need to go to the end of the last line of text and
then paste there, so you'd need to F2, then END, then CTRL-V

Does this make sense?
 
If you just want to ENTER the date and time you should be able to press
CONTROL + : (for the date)
and
CONTROL + ; (for the time)

Unless you have the button as a menu item or on a button bar Access
won't know WHERE in the control to paste the date and time. You can use
Previous Control to determine which control to paste the value into.

In other words this is not quite as simple as one might think.

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 
I have what I think is probably a simple thing to do, but I can't
figure out how.

I want to have a button that paste's the current date and time at the
cursor in any field. Is this possible or do I need to utilize API's
and such to do this?

If you set focus to a textbox or other editable control on a form, and press
Ctrl-; (control semicolon), it will insert the current date and time. Is that
what you mean?

A command button on the Form will be really hard to implement because it won't
have any way to determine WHICH control you mean.
 
Back
Top