Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem measuring elapsed time 2

Status
Not open for further replies.

hoose

Technical User
Jun 5, 2003
43
CA
Hi everyone,

I want to measure how long it takes to enter data into my forms.

At the beginning, i have

Forms![Introduction]![STTIME] = Now

and at the end i have

Forms![Introduction]![ENDTIME] = Now
Fomrs![Introduction]![INTTIME] = DateDiff ("n", Forms![Introduction]![ENDTIME], Forms![Introduction]![STTIME])

the STTIME (start time) variable has the correct start time, and the ENDTIME (end time) variable has the correct ending time. However, the value of INTTIME (interview time or elapsed time) is always 0. I don't understand why DateDiff will not calculate the elapsed time.

The three variables are all data types, set to short time format.

Does anyone know what I'm doing incorrectly?

Thank you in advance.

Dan
 
n is minutes. Is there a difference of several minutes between the two times?
 
I've tried it with different times ranging from 3 minutes to about 12 minutes.

Does the code appear to be correct?
 
does short date format support time. I thought that just set the time value at midnight at the beginning of the date.
 
the short time format displays time hh:mm

could the problem be because i have datediff in minutes and the time format in hours and minutes?

dan
 
Don't know. First try changing the date diff to seconds and see what happens.

Is this in a class module that is part of a form? If it is, try referring to the start time and end time text boxes as Me!StTime and Me!EndTime. You could also try moving the values from the text boxes to variables and then use the variables as inputs to the data diff function.
 
To be absolutely sure VB is correctly converting the textbox values, explicitly convert them to Date type before using them. Like so:

Code:
'At the beginning, i have

Forms![Introduction]![STTIME] = Now

'and at the end i have

Forms![Introduction]![ENDTIME] = Now
Fomrs![Introduction]![INTTIME] = DateDiff ("n", CDate(Forms![Introduction]![ENDTIME]), CDate(Forms![Introduction]![STTIME]))


--
Find common answers using Google Groups:

Corrupt MDBs FAQ
 
I used the CDate function to ensure that i was working with dates, but nothing changed.

Does 'Now' only return the date, not the time?

 
Dear Hoose,

Dates and times are tricky little items.
You are moving date/time to a text field, so I think access does not understand what you are trying to do with the inputs on your date calculation.

Try this:
[Blue]
Dim MyStartDate as Date
Dim MyEndDate as Date

MyStartDate = Now
Forms![Introduction]![STTIME] = MyStartDate
[Black]
and at the end try:
[Blue]
MyEndDate = Now
Forms![Introduction]![ENDTIME] = MyEndDate
Forms![Introduction]![INTTIME] = DateDiff ("n", MyEndDate, MyStartDate)

[Black]
Hope This Helps,
Hap [2thumbsup]



Access Developer [pc] - [americanflag]
Specializing in Access based Add-on Solutions for the Developer
 
Now() is both date and time.
Date() is the date only.
Time() is the time only.


I assume STARTTIME and ENDTIME are textboxes...if so, check what values are stored in those textboxes. I think you have set them up somehow different from the standard way. Set the formatting to "General" or "Text" or the default, and see if it now stores the time. Remove any input mask you may have set. It should work now.


If you need to store the date value into a "formatted" textbox, you can play with the Format(Now(), "your custom date format here, i.e. yyyy/mm/dd hh:nnap") function instead of the Now() function.

--
Find common answers using Google Groups:

Corrupt MDBs FAQ
 
Dear Hoose,

In my example, I just copied your code.

You should Reorder the date calc
Yours: [Red]
Forms![Introduction]![INTTIME] = DateDiff ("n", MyEndDate, MyStartDate) [Black]
will produce a negative time in minutes
Should be: [Blue]
Forms![Introduction]![INTTIME] = DateDiff ("n", MyStartDate, MyEndDate) [Green]
will produce a Positive time in minutes
[Black]
Later,
Hap...

Access Developer [pc] - [americanflag]
Specializing in Access based Add-on Solutions for the Developer
 
hi everyone

i tried what hap007 suggested and everything works fine.

Does anyone know why it wouldn't work the way I orginially had them?

dan
 
and thanks for all your suggestions

dan
 
Dear Hoose,

I can see 2 possible problems

1) You spelled 'Forms' incorrectly
2) You moved your date to a text field, but did not tell access that you had dates and times stored in those fields.
Your line: [Red]
Fomrs![Introduction]![INTTIME] = DateDiff ("n", Forms![Introduction]![ENDTIME], Forms![Introduction]![STTIME])
[Black]
May have worked if you typed it: [Blue]
Forms![Introduction]![INTTIME] = DateDiff ("n", #Forms![Introduction]![ENDTIME]#, #Forms![Introduction]![STTIME]# )
[Black]
Later,
Hap...

Access Developer [pc] - [americanflag]
Specializing in Access based Add-on Solutions for the Developer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top