Time difference and If function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to calculate difference betwen last update and current time:

Dim sngElapsedTime As Date
Dim Last_Update As Date
Dim sMsg As String

sMsg = " Please update" & " " & [Ticket #]
'determine the amount of time that has elapst between when the form
'was open and now.
sngElapsedTime = Now() - [Last Update]
'Update the timer
txtTimeDiff = Format(sngElapsedTime, "hh:mm")

How can I write if function that will display message after differnce is >
59 minutes?

Thanks
 
Use DateDiff() to get the difference in whole minutes:

Dim lngMinutes As Long
lngMinutes = DateDiff("n", [Last Update], Now())

You can display that as hours an minutes with:
= lngMinutes \ 60 & Format(lngMinutes Mod 60, "\:00")
 
Thanks Allen however:
I am calculating time difference using
sngElapsedTime = Now() - [Last Update]
and everything is ok
Then i am updating time differnce every minute using on timer event
txtTimeDiff = Format(sngElapsedTime, "hh:mm")

I would like to write if function that will display message box after time
difference > 59 minutes. I dont know how to set this function.

If sngElapsedTime > 59 Then
MsgBox(sMsg, vbCritical .....
Msgbox is displayed even if difference is less then 59 minutes


Allen Browne said:
Use DateDiff() to get the difference in whole minutes:

Dim lngMinutes As Long
lngMinutes = DateDiff("n", [Last Update], Now())

You can display that as hours an minutes with:
= lngMinutes \ 60 & Format(lngMinutes Mod 60, "\:00")

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Greg said:
I am trying to calculate difference betwen last update and current time:

Dim sngElapsedTime As Date
Dim Last_Update As Date
Dim sMsg As String

sMsg = " Please update" & " " & [Ticket #]
'determine the amount of time that has elapst between when the form
'was open and now.
sngElapsedTime = Now() - [Last Update]
'Update the timer
txtTimeDiff = Format(sngElapsedTime, "hh:mm")

How can I write if function that will display message after differnce is >
59 minutes?

Thanks
 
Thanks Allen however:
I am calculating time difference using
sngElapsedTime = Now() - [Last Update]
and everything is ok

Everything is not ok, or you would not have posted your original
question, which Allen answered.

If you were to examine the result of your Now() - [Last Update],
you will see that it's the fractional part of the day.
That is 6 hours = .25. 1 hour is approx. 0.0416667

Do the calc as Allen showed you and you get a result in minutes,
which you can test with if intElapsedTime >= 60

Q
Then i am updating time differnce every minute using on timer
event txtTimeDiff = Format(sngElapsedTime, "hh:mm")

I would like to write if function that will display message box
after time difference > 59 minutes. I dont know how to set this
function.

If sngElapsedTime > 59 Then
MsgBox(sMsg, vbCritical .....
Msgbox is displayed even if difference is less then 59 minutes


Allen Browne said:
Use DateDiff() to get the difference in whole minutes:

Dim lngMinutes As Long
lngMinutes = DateDiff("n", [Last Update], Now())

You can display that as hours an minutes with:
= lngMinutes \ 60 & Format(lngMinutes Mod 60, "\:00")

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Greg said:
I am trying to calculate difference betwen last update and
current time:

Dim sngElapsedTime As Date
Dim Last_Update As Date
Dim sMsg As String

sMsg = " Please update" & " " & [Ticket #]
'determine the amount of time that has elapst between when
the form 'was open and now.
sngElapsedTime = Now() - [Last Update]
'Update the timer
txtTimeDiff = Format(sngElapsedTime, "hh:mm")

How can I write if function that will display message after
differnce is > 59 minutes?

Thanks
 
That's correct: the method you are using will not work.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Greg said:
Thanks Allen however:
I am calculating time difference using
sngElapsedTime = Now() - [Last Update]
and everything is ok
Then i am updating time differnce every minute using on timer event
txtTimeDiff = Format(sngElapsedTime, "hh:mm")

I would like to write if function that will display message box after time
difference > 59 minutes. I dont know how to set this function.

If sngElapsedTime > 59 Then
MsgBox(sMsg, vbCritical .....
Msgbox is displayed even if difference is less then 59 minutes


Allen Browne said:
Use DateDiff() to get the difference in whole minutes:

Dim lngMinutes As Long
lngMinutes = DateDiff("n", [Last Update], Now())

You can display that as hours an minutes with:
= lngMinutes \ 60 & Format(lngMinutes Mod 60, "\:00")

Greg said:
I am trying to calculate difference betwen last update and current time:

Dim sngElapsedTime As Date
Dim Last_Update As Date
Dim sMsg As String

sMsg = " Please update" & " " & [Ticket #]
'determine the amount of time that has elapst between when the form
'was open and now.
sngElapsedTime = Now() - [Last Update]
'Update the timer
txtTimeDiff = Format(sngElapsedTime, "hh:mm")

How can I write if function that will display message after differnce
is >
59 minutes?

Thanks
 
Back
Top