Timing function in Access 2003

S

springschick

I have been asked to add a timer feature to a form. This timer would keep
track of how much time was spent on the form. For example, the user would
open the form, set their information and click a button that says Start Time
or something to that effect. When they were done, they would hit a button
that says End Time, and the elapsed time would be recorded in the table via
the form. I do not know if this is possible, or if it is, how to do it. Any
help would be most appreciated. Thank you!
 
B

Beetle

Do you need some kind of running timer to actually be
displayed on the form while the urers are working with it,
or do you just need to store the values so you can calculate
the elapsed time?

If the latter, then I would just add two fields to the table
(StartTime and EndTime), then put two command buttons
on the form (cmdStart and cmdEnd), then put a simple
line of code behind the Click event of those command buttons.
Example;

Private Sub cmdStart_Click

Me!StartTime = Now()

End Sub

Private Sub cmdEnd_Click

Me!EndTime = Now()

End Sub

Then you would use a calculated field in a query, or perhaps
a calculated control on a form to calculate the elapsed time
based on those values. I would not try to store the elapsed time.

Depending on how your form is set up, etc. you may need a
couple of additional measures to prevent a user from overriding
an existing Start or End time value.
 
S

springschick

I will try that. However, I have never worked with time functions before and
would need help on how to calculate the elapsed time. It does not need to be
displayed, merely recorded. Just as some background, this is for an online
poker player who would like to record the time he plays in each of his
sessions.

Like I said, I have not worked with time functions before. How would I write
the calculation?

Thanks.
 
B

Beetle

Well in this case you would use the DateDiff function to return
the difference between the StartDate and EndDate.
The DateDiff function can return values in many different intervals
(seconds, minutes, hours, days, weeks, etc., etc.). You can find
info about it in Access help.

The result you get back from DateDiff will be a long integer value.
You would then manipulate that value depending on how you
want the result displayed. Below are a couple of examples.

Example 1

Supposing that you just want to display a number representing
the number of Hours.Minutes. You could use;

DateDiff("n", [StartDate], [EndDate])/60

This would return results like;

0.5 (1/2 hour)
5.0 (5 hours)

Example 2

Supposing that you want to display hours, minutes and seconds
in a time format, you could use;

Format(DateDiff("s", [StartDate], [EndDate])/86400, "hh:mm:ss")

This would return results like;

00:30:00 (1/2 hour)
05:00:00 (5 hours)
 
D

Douglas J. Steele

If Me!NameOfYourButton.Caption = "Enter End Time" and If
Me!NameOfYourButton.Caption = "Enter Start Time" are both invalid syntax.
That code would not even compile, much less do anything useful.
 
J

John... Visio MVP

Unfortunately, he has made at least ten posts this month soliciting work.
That is almost a post a day.

John... Visio MVP
BruceM via AccessMonster.com said:
If you are going the route you suggest would in any case need to change
the
caption (and set its value in the form's Current event, probably), which
your
code does not show. I'm not sure what is incorrect about the syntax of
the
cited lines, but I do count three Ifs and just one End If in the original
code you posted. As you said, you made a posting error, which we all have
done.

If you have a disagreement with an MVP, take it up with that person. MVPs
are individuals, not a monolithic group except in that all have
demonstrated
expertise with Access.

Let's not get into who should be feeling shame. Lately you have been
posting
in the spirit of the newsgroups (i.e. without soliciting money), but I'm
probably not alone in waiting for the other shoe to drop (again).
I admit to making an error. I copied those lines but forgot to drop the
"If". Wouldn't it have been more helpful and more polite to say why both
lines of code are invalid syntax than to be hypercritical? Oooops I forgot
... that's not how an MVP acts!!!!

And as far as doing something useful, after making the corrections to the
code, one button can enter both the Start Time and End Time alleviating
the
possibility of hitting the wrong button with two buttons. Again you ought
to
be ashamed signing MVP after your name when you are so hypercritical.

Steve
If Me!NameOfYourButton.Caption = "Enter End Time" and If
Me!NameOfYourButton.Caption = "Enter Start Time" are both invalid
syntax.
[quoted text clipped - 28 lines]
Any
help would be most appreciated. Thank you!
 
J

James A. Fortune

BruceM said:
I should have been specific about Access MVPs being the ones with Access
expertise. In any case, many MVPs have not bothered to reply to you at all,
and some who have replied have done so with arguably more courtesy than you
deserve. Judging all of a group by the actions of some of its members,
whether you perceive those actions as good or bad, is prejudicial at least.

I believe that Douglas Steele is every bit deserving of Microsoft's MVP
status in terms of both expertise and volume of posts. Indeed, I often
wonder how he gets the time to answer as many posts as he does with such
a high level of effectiveness. In pointing out the error in Steve's
code, he was matter-of-fact about it. Although he could have done more
to couch his language, a matter-of-fact style is not outside the bounds
of decorum IMO, especially toward someone who has obviously not earned
his respect. I keep a mental list of people who would be on my personal
MVP list. That list is not very long. Douglas Steele is on that list.
Steve is not.

James A. Fortune
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top