To-day's date updated after any entry (1 Viewer)

access2010

Registered User.
Local time
Today, 02:18
Joined
Dec 26, 2009
Messages
1,021
Hello.

Could I please receive a suggestion on how to have the field = ResearchDate = updated with to-days date, no matter which field new data has been entered into?

Thank you,
Nicole
 

Attachments

  • Date_After_Update=338.mdb
    388 KB · Views: 99

theDBguy

I’m here to help
Staff member
Local time
Today, 02:18
Joined
Oct 29, 2018
Messages
21,454
Hi Nicole. Have you tried using the Form's BeforeUpdate event? Just curious...
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 05:18
Joined
May 21, 2018
Messages
8,525
You may also want to try the forms Dirty event. This happens prior to leaving the record.
 

access2010

Registered User.
Local time
Today, 02:18
Joined
Dec 26, 2009
Messages
1,021
Hi Nicole. Have you tried using the Form's BeforeUpdate event? Just curious...

theDBguy, thank you for the suggestion, how should the = BeforeUpdate = be used?​

Nicole​

You may also want to try the forms Dirty event. This happens prior to leaving the record.

MajP, thank you for the suggestion, how should the = Dirty Event = be used?​

Nicole​

 

MajP

You've got your good things, and you've got mine.
Local time
Today, 05:18
Joined
May 21, 2018
Messages
8,525
In either case your code would be

ResearchDate = Date()

Pick one of the events. Click on the ellipses to create the event procedure. Add the code
 

access2010

Registered User.
Local time
Today, 02:18
Joined
Dec 26, 2009
Messages
1,021
In either case your code would be

ResearchDate = Date()

Pick one of the events. Click on the ellipses to create the event procedure. Add the code
Majp, thank you for your suggestion, which does not work the way we would like.

This is the code in the date field
Private Sub ResearchDate_LostFocus()
Me.ResearchDate = Date
End Sub

The above code works when the cursor leaves the date field, but I would like to have the DATE updated when the cursor leaves any of the fields.
Do you have a suggestion on how to this?

Crystal
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:18
Joined
Oct 29, 2018
Messages
21,454
Majp, thank you for your suggestion, which does not work the way we would like.

This is the code in the date field
Private Sub ResearchDate_LostFocus()
Me.ResearchDate = Date
End Sub

The above code works when the cursor leaves the date field, but I would like to have the DATE updated when the cursor leaves any of the fields.
Do you have a suggestion on how to this?

Crystal
Did you already try the Form's BeforeUpdate event?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 04:18
Joined
Feb 28, 2001
Messages
27,140
Note that nothing is saved until you actually do something to save the current contents. Which is pretty much automatic if you navigate to another record and the form is dirty. But your question was sufficiently unclear for me to not be sure that is what you were thinking to do. Can you be just a little bit more specific about (mechanically) what you want to do in order to make this date get updated? Remembering that if you don't trigger a save, NOTHING gets updated right away.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 05:18
Joined
May 21, 2018
Messages
8,525
Majp, thank you for your suggestion, which does not work the way we would like.
You will have to explain that because that is the only code that would do what you are saying, unless you are not being clear. This and the before update will do the same thing. The difference is the dirty event will happen without having to leave the record, the before update will do it when you leave the record.

If you want to do this for many fields but not all then build a function.

Public Function SetResearchDate()
me.researchdate = date()
end function

Then for every control you want this to happen, select them all. In the after update property type in
=SetResearchDate()
 

missinglinq

AWF VIP
Local time
Today, 05:18
Joined
Jun 20, 2003
Messages
6,423
Using the LostFocus event of a Control will update the Record...even if you simply move thru the Control...without making any change!

As suggested...you need to use the Form's BeforeUpdate event. This will only fire if you make a change to any Control:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
  Me.ResearchDate = Date
End Sub
Linq ;0)>
 

Isaac

Lifelong Learner
Local time
Today, 02:18
Joined
Mar 14, 2017
Messages
8,774
Using the LostFocus event of a Control will update the Record...even if you simply move thru the Control...without making any change!
Well, in @MajP 's defense, technically, there wouldn't be any problem. Because if "without making a change" ends up being the case, then the ResearchDate won't be updated either..

Either will work
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:18
Joined
Feb 19, 2002
Messages
43,223
Access 2010, you put the code in the WRONG event. That's why it doesn't work. Use the Form's BeforeUpdate event as theDBGuy suggested. The Form's on Dirty will work but I prefer the Form's BeforeUpdate to keep the date setting with all the form's validation code.
 

access2010

Registered User.
Local time
Today, 02:18
Joined
Dec 26, 2009
Messages
1,021
Thank you ALL for your suggestions.
I had placed the suggested code in the wrong place and now that the code is in the = BeforeUpdate event = we receive the results wanted.
Crystal
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:18
Joined
Oct 29, 2018
Messages
21,454
Thank you ALL for your suggestions.
I had placed the suggested code in the wrong place and now that the code is in the = BeforeUpdate event = we receive the results wanted.
Crystal
Hi Crystal. Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Top Bottom