Code to launch the current date (1 Viewer)

Valient

Member
Local time
Today, 14:48
Joined
Jun 21, 2021
Messages
48
Hi Eveyone,

Can someone please help me to create code as per below screenshot.
The purpose is once I click the button "BTN" it will display the current date in the unbound "LDate"
1630997768214.png

The date should be displayed until I close and open again the access file.
The date will be replaced only with the new one once I click again the BTN.

Thank you
 

isladogs

MVP / VIP
Local time
Today, 11:48
Joined
Jan 14, 2017
Messages
18,186
Is this all you want?
Code:
Private Sub BTN_Click()
    Me.txtBoxName=Date()
End Sub
 

Valient

Member
Local time
Today, 14:48
Joined
Jun 21, 2021
Messages
48
Is this all you want?
Code:
Private Sub BTN_Click()
    Me.txtBoxName=Date()
End Sub
Yes it works, when I click the BTN it display the current date on the txtBox

1631002587901.png


However, when I close and open again the access file, the date is not available anymore.
1631002811175.png


It should be retained in the txtbox even I close it.
And once I open it again and click the BTN it should display the new date again....
 

CJ_London

Super Moderator
Staff member
Local time
Today, 11:48
Joined
Feb 19, 2013
Messages
16,553
Only way to do that is to bind the control to a field in a table or to store the value in a user defined property somewhere and have code to retrieve it when the form is opened

You will get a more focussed response if you explain the context of what you are trying to do
 

Valient

Member
Local time
Today, 14:48
Joined
Jun 21, 2021
Messages
48
Only way to do that is to bind the control to a field in a table or to store the value in a user defined property somewhere and have code to retrieve it when the form is opened

You will get a more focussed response if you explain the context of what you are trying to do
Hi, I add it as a field in a table and it works even I close it. Thanks

I just want to add to my query on how to display both date and time in the textbox?
I saw the General option under Format but it only show date

thanks
 

isladogs

MVP / VIP
Local time
Today, 11:48
Joined
Jan 14, 2017
Messages
18,186
Excellent. We were both pleased to help.
 

Valient

Member
Local time
Today, 14:48
Joined
Jun 21, 2021
Messages
48
Excellent. We were both pleased to help.
Hi, I would like to open again this query that you had resolved.

The button works fine, once click it display the current date and time (in "Ldate" textbook). This is after adding the "Ldate" as field in the table.
1631510056747.png


However, when I moved to the next row, the displayed date in "Ldate" text box disappeared as expected because the next row belongs to different ID
1631510241925.png


Is there a way that once I clicked the BTN the "Ldate" textbox value will be displayed in all rows?

Attached is the database for your reference.
 

Attachments

  • 1631509426980.png
    1631509426980.png
    15.1 KB · Views: 304
  • 1631509802912.png
    1631509802912.png
    13.7 KB · Views: 276
  • Database1.accdb
    480 KB · Views: 252

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:48
Joined
May 7, 2009
Messages
19,169
you do not need the BTN there.
bring your table in design view and
put the Default Value.

see also the Current event of the form
in case you already entered some data
with date/time stamp.
 

Attachments

  • Database1 (8).accdb
    512 KB · Views: 297

Valient

Member
Local time
Today, 14:48
Joined
Jun 21, 2021
Messages
48
you do not need the BTN there.
bring your table in design view and
put the Default Value.

see also the Current event of the form
in case you already entered some data
with date/time stamp.
hi arnelgp,

In the attachment you sent, the textbox display different value when moving to different row.

At row 02 Sep 2, it whos 11:02:24
1631520787994.png


At row 03 Sep it shows 11:00:56
1631521781951.png



The intention is that, at every row , it should shows the last date/time after clicking the BTN.

For the background
We are monitoring emails and we are using the database to record the information from outlook.
The textbox date will be our reference on when was the last date/time we check the outlook and recorded the information on the tool.

Then the idea of having a BTN came up, so that the last User just need to click it to display at which date/time he stopped checking the mail and updated the tool.

If you have better idea than BTN, please assist...
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:48
Joined
May 7, 2009
Messages
19,169
it will only update those records without "LDate"
 

Attachments

  • Database1 (8).accdb
    420 KB · Views: 320

Valient

Member
Local time
Today, 14:48
Joined
Jun 21, 2021
Messages
48
Hi arnelgp,

The single date/time is now displayed to all active rows once the BTN is clicked.
However, If you will click the button again to display the latest date/time, it still shows the previous result date/time.

The required is every time you click the BTN it will gives you the latest date/time and shows it to all rows.
This display date should stay there unless the button is click to get new date/time.

Also, as you are getting near to it...if possible to have the display like the below format from 13/09/2021 14:31:49 to 13-Sep-21 14:31:49
 

Gasman

Enthusiastic Amateur
Local time
Today, 11:48
Joined
Sep 21, 2011
Messages
14,038
So here is the code for the button.
See if you can work out what YOU need to change?

As to the control Ldate, set that to dte in the event code below.

It does not make any sense to me to change the date and time for any day in the past? :unsure:
Surely you just need for the day of use?


Code:
Private Sub BTN_Click()
Dim rs As DAO.Recordset
dte = Now()
Set rs = Me.RecordsetClone
Set rs = rs.Clone
With rs
    If Not (.BOF And .EOF) Then
        .MoveFirst
    End If
    Do Until .EOF
        If IsNull(!Ldate) Then
            .Edit
            !Ldate = dte
            .Update
        End If
        .MoveNext
    Loop
End With
Set rs = Nothing
Me.Recalc
End Sub
 
Last edited:

Valient

Member
Local time
Today, 14:48
Joined
Jun 21, 2021
Messages
48
So here is the code for the button.
See if you can work out what YOU need to change?

As to the control Ldate, set that to dte in the event code below.

It does not make any sense to me to change the date and time for any day in the past? :unsure:
Surely you just need for the day of use?


Code:
Private Sub BTN_Click()
Dim rs As DAO.Recordset
dte = Now()
Set rs = Me.RecordsetClone
Set rs = rs.Clone
With rs
    If Not (.BOF And .EOF) Then
        .MoveFirst
    End If
    Do Until .EOF
        If IsNull(!Ldate) Then
            .Edit
            !Ldate = dte
            .Update
        End If
        .MoveNext
    Loop
End With
Set rs = Nothing
Me.Recalc
End Sub
hi Gasman,

If you are receiving hundred of email per day from an auto email distribution and you need to check it one by one and do the action as needed then yes it is possible to change the date/time per day especially if there is shifting in the schedule, and it is actually happening.
 

Gasman

Enthusiastic Amateur
Local time
Today, 11:48
Joined
Sep 21, 2011
Messages
14,038
hi Gasman,

If you are receiving hundred of email per day from an auto email distribution and you need to check it one by one and do the action as needed then yes it is possible to change the date/time per day especially if there is shifting in the schedule, and it is actually happening.
OK, so work out what Arnel's code is doing. He actually told you that it would only update certain records as well?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:48
Joined
May 7, 2009
Messages
19,169
The required is every time you click the BTN it will gives you the latest date/time and shows it to all rows.
This display date should stay there unless the button is click to get new date/time
think again.
if one person has just checked 500 emails, then clicked the button, it "stamp" the field correctly.
another shift, another person, does the same for another 500, all records (1000) would be stamped
on same date/time.
this will go on and on.
and there is no telling which record was viewed on which date/time? all records have current date/time?
 

Valient

Member
Local time
Today, 14:48
Joined
Jun 21, 2021
Messages
48
think again.
if one person has just checked 500 emails, then clicked the button, it "stamp" the field correctly.
another shift, another person, does the same for another 500, all records (1000) would be stamped
on same date/time.
this will go on and on.
and there is no telling which record was viewed on which date/time? all records have current date/time?
hi arnelgp,
You are absolutely correct, thank you for your observation.

Yeah no need BTN, the User should manually select the date/time of the last email he has checked.
The flow will be as below:
>> A person has just checked 500 emails, then he will select the date/time of the last email he worked on let say 08-Sep-21 10:00:01
>> Another shift will check that log date and will start to check the emails from 08-Sep-21 10:00:02. Before leaving he will update the "Ldate" based on the last email date he has checked for the reference of the next shift . let say 08-Sep-21 14:00:08

Same concept as you did in the previous attachment for the BTN, would it be possible that the date to be selected manually in the "Ldate" text box can be automatically applied to ID/rows?
 

Users who are viewing this thread

Top Bottom