Tech Support Guy banner
Status
Not open for further replies.

Solved: Solved: Code Needed For A Timestamp

3K views 31 replies 6 participants last post by  slurpee55 
#1 ·
I am looking for some help on an access database. I am trying to create a form that will automate a time tracking for a task I need to perform daily. My needs are pretty straight forward.

1. I want a button that when clicked will enter the current date into a text box, but I also want the ability to type a date other than that into the same text box. I want the format to be MM/DD/YYYY.
2. I want a set of buttons (Start Time and End Time) that will do the same thing as above with a timestamp. Also, again the ability to type directly in the text field. I want the format to be HH:MM.

Is this something that is easily accomplished? I have some experience with code behind forms, but would appreciate any help you would offer.

Thanks!!
 
#2 ·
You should be able to just create your buttons and then your text boxes. Basically, the only command functions you need are the now and format functions, I think.

So your code would look something like this for the timestamp:

Code:
Private Sub timestamp_On_Click()
me.txtboxTimeStamp.value =format(Now(), "MM/DD/YYYY")
End sub
...for the start time

Code:
Private Sub starttime_On_Click()
me.txtboxStartTime.value =format(Now(), "HH:MM")
End sub
HTH
Roger
 
#7 ·
Use the sub-procedures that rconverse has put in his post and it should accomplish what you want as well. I was just giving you a hotkey option. Do you know how to add that VBA in and have it run?
 
#9 ·
OBP,

I believe I do need them for what I am trying to do.

jimr,

I have done some things in code before and believe I am doing it right, but I could be wrong. When I do with the provided code it throws the above error. I made sure I changed the names in the code to reflect my control names, so I don't think it's something I did - but I'm not an expert. Should I post the DB or can someone talk me through it?
 
#22 ·
The total time is only for one person, but I want it stored in the DB for reporting purposes. The thought process is to be able to input a date range into the query and have it return the daily totals within that range (weekly totals, monthly totals and such).
 
#26 ·
If you want to store the data in the table then assuming it has a name like "Hours_Worked" then you would create some VBA in the After Update Event Procedure of the End field on the Form.
me.[Hours_Worked] = me.[End] - me.[Start]
Will Shifts come in to this equation because the Time's hours after midnight are actually less than thos before and will generate an error.
 
Status
Not open for further replies.
You have insufficient privileges to reply here.
Top