Access form Timestamp (1 Viewer)

jpl458

Well-known member
Local time
Yesterday, 17:46
Joined
Mar 30, 2012
Messages
1,038
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
 

CJ_London

Super Moderator
Staff member
Local time
Today, 01:46
Joined
Feb 19, 2013
Messages
16,627
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()
 

XPS35

Active member
Local time
Today, 02:46
Joined
Jul 19, 2022
Messages
159
Try

Code:
Private Sub datebox_Click()
    Me.datebox = Now()
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:46
Joined
Oct 29, 2018
Messages
21,485
Duplicate thread?
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:46
Joined
Sep 21, 2011
Messages
14,336
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
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:46
Joined
Sep 21, 2011
Messages
14,336
Duplicate thread?
Presumably did not like the responses?
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 20:46
Joined
Feb 19, 2002
Messages
43,328
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.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 19:46
Joined
Feb 28, 2001
Messages
27,208
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

Top Bottom