set value to record date and time (1 Viewer)

rainbows

Registered User.
Local time
Today, 11:29
Joined
Apr 21, 2017
Messages
425
this marco i found on an old database that records the date and time when the stockqty gets changed via the after update event
so i thought i could do the same think on a new database but i cannot find the "setvalue" from the dropdown box can you please advise what i am doing wrong

thanks steve



1689357601332.png
 

rainbows

Registered User.
Local time
Today, 11:29
Joined
Apr 21, 2017
Messages
425
thank you , now working

steve
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 14:29
Joined
Feb 19, 2002
Messages
43,277
this marco i found on an old database that records the date and time when the stockqty gets changed via the after update event
Are you saying that you are using the stockqty's AfterUpdate event? That is OK but using the Form's AfterUpdate event to update a column in the record is very wrong because the Form's AfterUpdate event does not run until AFTER the record gets saved and so updating fields in the Form's AfterUpdate event puts the form into a loop. The record gets saved, you dirty the record so you have to save it again, the afterUpdate event runs which dirties the record so it has to get saved and then the AfterUpdate event runs again -- essentially never ending. However, newer versions of Access are smart enough to recognize this type of endless loop by examining the entries in the stack and then exiting the loop gracefully.
 

rainbows

Registered User.
Local time
Today, 11:29
Joined
Apr 21, 2017
Messages
425
this is how i have done it .is that correct?


1689444823830.png
 

rainbows

Registered User.
Local time
Today, 11:29
Joined
Apr 21, 2017
Messages
425
since checking what pat asked i have checked something and it is not quite doing what i would like it to do
when i type the qty into the stockqty field the datemodified works ok . but with my latest modification to the form it will not work

in the form below you can see a stock qty of 1260 if i change that manually the date /time will be recorded but having automated this function with an append query that stock will changes when i tick the "stock change" button but the datemodified dont. can i get it to do it both ways ?

steve
1689447789394.png
 

Attachments

  • 1689447609625.png
    1689447609625.png
    235.6 KB · Views: 43

Pat Hartman

Super Moderator
Staff member
Local time
Today, 14:29
Joined
Feb 19, 2002
Messages
43,277
1. Use ONE field to hold date/time, not two. Two just makes more work for you.
2. I never use macros. If you only want to update the modified date when the quantity changes, then in the AfterUpdate event of the quantity control, put.

Me.DateModified = Now()
FYI, you are already doing this. Now() = date AND time but Date() = just today's date. Therefore, DateModified already includes date + time. If you had really wanted it to only contain just the date, you should have used Date() rather than Now()

3. The code behind the form runs only when the record is changed using the form. If you also run update or append queries and you want those to also reflect the modified date, you would include the ModifiedDate column in the columns to update. Set its value to Now().
3a. You should probably switch to using a Data Macro instead. I don't use Data Macros because they apply only to ACE and most of my BE's are SQL Server so if you can't figure this out from the documentation (I didn't see an example that does what you want to do), someone else can probably help better. I don't know if the Data Macro can be set to run when only a specific column is changed or if the DM can use an IIf() to compare the current/old values for a column and use that to determine when to run. If you can't distinguish, using the data macro whether a specific column was changed, then stick with VBA in the quantity control on the form for the manual changes. Append queries would just populate the ModifiedDate but Update queries would have to have an IIf() to decide whether or not to update the ModifiedDate.

So, Data Macros, if they can be controlled at the column level would be a one-stop-shop way to handle the problem and you would remove the code from the AfterUpdate event. But, if Data Macros can't be controlled at the column level, then you have three different ways to do the update but you will be able to accurately control updating the ModifiedDate.
 

rainbows

Registered User.
Local time
Today, 11:29
Joined
Apr 21, 2017
Messages
425
I have removed the macro and did you you advised and changed the append query to include the datemodified and all seems to be ok
thank you will test again later today with real data not my test data
 

Users who are viewing this thread

Top Bottom