Button to add time to table (1 Viewer)

Pat Hartman

Super Moderator
Staff member
Local time
Today, 02:12
Joined
Feb 19, 2002
Messages
42,981
Never make the user do something you can do for him. Access forms provide a variety of events for you to use to run code depending on what you need to do. To log time to update, Use the Form's on Dirty event to log the start time:

SaveStartTime = Now()

Then use the Form's AfterUpdate event to log end time:

SaveEndTime = Now()

Follow that by an append query to log the times.

If you actually want to keep the times in the record being updated (I wouldn't do this), Use the Form's BeforeUpdate event to record the end time and follow that with:
Me.StartTime = SaveStartTime
Me.EndTime = SaveEndTime

And when the record is saved, so are the times. No need for an append or update query.
 

Jolland26

New member
Local time
Today, 06:12
Joined
Sep 14, 2020
Messages
22
Never make the user do something you can do for him. Access forms provide a variety of events for you to use to run code depending on what you need to do. To log time to update, Use the Form's on Dirty event to log the start time:

SaveStartTime = Now()

Then use the Form's AfterUpdate event to log end time:

SaveEndTime = Now()

Follow that by an append query to log the times.

If you actually want to keep the times in the record being updated (I wouldn't do this), Use the Form's BeforeUpdate event to record the end time and follow that with:
Me.StartTime = SaveStartTime
Me.EndTime = SaveEndTime

And when the record is saved, so are the times. No need for an append or update query.
Thanks for your help Pat. I don't want to record how much time the user spends in the form itself, especially as they may have to add new information several times over several days. I would just like to know roughly how long between them first starting work on the Engineering Change, to when they finish completely. This is why I was going to use a button, although for the EndTime button I want to incorporate it into my email button at the end of the process. I think my original problem is somewhere within my database itself, now that I'm WFH I think there's been some corruption so I'm going to try creating a new database and import the tables from this one into it and try again.
 

Gasman

Enthusiastic Amateur
Local time
Today, 06:12
Joined
Sep 21, 2011
Messages
14,048
OK, what is to stop me setting the start time an hour after I actually do start the job, plus enter a completed time an hour before I really finish.?
Are the employers going to count all those periods and expect to get 8 hours or whatever your working day is?

Is there a benefit to me going the other way and increasing the time taken for the job.?

I would perhaps take the time the form is opened and a job allocated.?
Then when the job is completed and notes added to explain the work carried out and close the job, then save the end time.

It can still be manipulated, but not as easy.?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 02:12
Joined
Feb 19, 2002
Messages
42,981
Finding the time they spent on the form is easy enough as I described. Relying on the user to remember to click buttons for start and finish, not so much. Also, when they press the button, if you go that way, the time could be entered automatically which saves them some work and if they can be relied upon to press the begin and end buttons, then, you might as well save them the effort of typing the date/time.
 

Jolland26

New member
Local time
Today, 06:12
Joined
Sep 14, 2020
Messages
22
It will rely on my users being truthful, but for the application that I am using it for it's not a huge problem if they don't press the button. I also do have a code that is logging what users are doing what in the database which they won't be able to see, so I can double check that they have input it correct. All I want these buttons to do is enable them, and managers, to quickly see roughly how much time (to the nearset hour) has been spent on a particular engineering change. However, as I said before, this will take them longer than they will spend in the form so I don't want to just track what time they open and close the form, just the time they first open it and then the final time they close it once the job is complete.
 

Users who are viewing this thread

Top Bottom