If statements with times - possible issue with the formatting of t

G

Guest

Hello,

I have a form with a start and a finish time (2 text boxs), and another text
box call WAITING_TIME that calculates the difference. I'm trying to execute
some code if that waiting time is less than one minute.

I've tried to use this code in the After Update event of the finish time:

If DateDiff("n", Me.START_TIME, Me.FINISH_TIME) <= #12:01:00 AM# Then
Do While Len(Me.OBSERVATIONS.Value) = 0
MsgBox "The processing time is unusually short. Please enter notes
exaplining the reason ", , "Short Process Time"
Me.OBSERVATIONS.SetFocus
Loop
End If

I've tried changing the #12:00:01 AM# with a "1" (since datediff calculates
the difference in minutes)

I have also tried using the WAITING_TIME value instead of the datediff
function:

If Me.WAITING_TIME <= #12:01:00 AM# Then...

Also tried

If Me.WAITING_TIME <= 0.000694444444444444 Then...
(0.000694444444444444 is the numeric equivalent of 1 minute, at least in
Excel)

Does anybody have an idea of why this If statement is not triggered when
that wait time is less than one minute?

Thanks!
 
G

Guest

I've tried changing the #12:00:01 AM# with a "1" (since datediff calculates
the difference in minutes)
Omit the quotes from the 1. Quotes make it text and not a number.
 
G

Guest

Karl, the quotes were only in my message. I didn't put them in the code.
Something else is creating the problem.
 
G

Guest

The DateDiff does not return a time, it returns a duration. If you are
trying to determine if the duration is less than one minute

If DateDiff("n", Me.START_TIME, Me.FINISH_TIME) < 60
 
G

Guest

I made a mistake in my previous post. I thought I read you were returning
seconds, but it is minutes, so <= 1 should work. You might try changing the
DateDiff to return seconds and use < 60.
 
G

Guest

Klatuu, I'm afraid that you are incorrect. "n" is the format for minutes; if
I made the expression <60 I would trigger the code every time the difference
in times is less than 1 hour (60 min).

However, the formula seems to be working now. I just compacted and repaired
the database and it started working.

Thanks!
 
G

Guest

I know, if you read my second post, you would see that I corrected myself.
Glad you got it working.
 

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