Access form Timestamp

jpl458

Well-known member
Local time
Today, 14:11
Joined
Mar 30, 2012
Messages
1,218
Creating a data entry form, and need to have a timestamp of date and time appear in a textbox from code in the onclick event of that text box. I can get the date in the box using
Me.datebox = Date
And can get the time using
Me.datebox = Time
But if I use
Me.datebox = Date / Time
I get a date 3/18/2214 and no time.
In the property sheet for the control, under format, there is no date / time format listed. So how do I create a timestamp?

I have the field in the table that will receive the timestamp when updated formatted as Date/Time.

Thanks
 
use the now function, not the date function. For a timestamp you normally set the field default value to now() and disable and/or lock the control if it appears on a form.

Using the default value means the field gets populated when the user starts to create a record. Sometimes it is more appropriate to set the timestamp when the user saves the record - in which case you use the form beforeupdate event to set the time using timestamp=now()
 
Try

Code:
Private Sub datebox_Click()
    Me.datebox = Now()
End Sub
 
Duplicate thread?
 
Creating a data entry form, and need to have a timestamp of date and time appear in a textbox from code in the onclick event of that text box. I can get the date in the box using
Me.datebox = Date
And can get the time using
Me.datebox = Time
But if I use
Me.datebox = Date / Time
I get a date 3/18/2214 and no time.
In the property sheet for the control, under format, there is no date / time format listed. So how do I create a timestamp?

I have the field in the table that will receive the timestamp when updated formatted as Date/Time.

Thanks
I have no idea why you would want to divide date by time?
Code:
? date
25/08/2022 
? time
16:08:08 
? cdate(date / time)
11/05/2082 05:57:35
 
Duplicate thread?
Presumably did not like the responses?
 
As I said in your other thread, you probably want to just post the data yourself rather than require the user to click on something to make it happen. I do this with most of my forms. Every table has a ChangeDT and a ChangeBy field. In the form's BeforeUpdate event as the last two lines, I use.

Me.ChangeDT = Now()
Me.ChangeBy = Environ("UserName")

There are other ways to get ChangeBy. This is the simplest.
 
As others stated, NOW() will get you date/time, date() will get you just the date, and time() will get you just the time. I made a video that shows how to automate Date/Time + Username anytime a change is made in a form so you don't need to hit a button. It does require some VBA code, but I did provide a link to the code in the video description.

Video:

While your link is indeed relevant, it has been pointed out that it might violate forum rules about advertising your offerings, particularly given your screen name which aligns with the name shown in the video. If your goal is advertising, you need to clear that with our site owner, Jon. This is not a "free advertising" site. Tossing your video in a topic-related forum to build up its hit count is also a form of advertising, since YouTube videos CAN be monetized.

Because the link was relevant to the thread in which it was posted, I am not accusing you of anything. However, a report WAS filed and as a moderator, it is my job to respond to reported questionable behavior.
 

Users who are viewing this thread

Back
Top Bottom