Entering the current Date and Time in a field

  • Thread starter Thread starter snsd
  • Start date Start date
S

snsd

Guest
I am a complete newbie. With some help, I managed to compile the following code to enter the Date and Time in a field on a form whenever you click on the field. I would like to change the functionality so that the Date and Time is entered when I type the letter "n" in the field versus when I click on the field. I'm hopelessly struggling with the event "On Key Press". I'm not even sure it will do what I want it to do.

Bottom line: What is the most effective way of entering the current date and time in a field outside of using Access's built-in ctrl+: and ctrl+shift+: keyboard commands. (I'm also open to using a command button or other efficient way to accomplish the same task.)

Private Sub VendorInformationAvailableDateAndTime_Click()
Me.VendorInformationAvailableDateAndTime = Now()
End Sub

I do NOT want the field to default to the current date and time. I need to have the ability to enter the current date and time at my option.

Any help is appreciated.

Dave
 
Date

How about dbl clicking on the field to enter the date/time.

Put this in the On DblClick Event of the field.

Me.fieldname = Now()
 
Thanks for the response. Actually, when I double click on the field, I have a "date-picker" calendar that pops-up where I can select a date other than today. So, I was thinking of using "On Key Press" event as an alternative. Any other ideas?

Thanks,

Dave
 
Put a little [small] command button beside the field. Code it to insert the date or time into that field you want. Put a messge in the Tool Tip so the user will know what it is for if they hover their mouse over it. Or better yet, add a conditional message box asking the user if they want to insert the date/time in the xyz field.
 
Thanks for the response. However, I'm a real newbie and have no idea how to "code it". If you can point me to something that will help to write the code, that'd be great.

Dave
 
Date

Draw a button on the form.
In the On Click Event put the following code:

Dim strMsg As String
strMsg = "Do you want to insert the date?."
If MsgBox(strMsg, vbYesNo, "") = vbYes Then

Me.VendorInformationAvailableDateAndTime = Now()
Else
End If
 

Users who are viewing this thread

Back
Top Bottom