Rounding time to next 15 minutes

  • Thread starter Thread starter Mary McKechnie
  • Start date Start date
M

Mary McKechnie

Hello:
I'm using Access 97 and am calculating Therapeutic
session length based on a start and stop time...does
anyone know of an easy way to have the session length
round to the next 15 minute interval?
Thanks,

Mary
 
The following code will do this

On a form add a Text box and Name it Tm
Enter you time in this Text box

Add a Button and copy the following code to on click event

'Start
'==============================================
Dim MyTime, Hr, Mn, Sc, X
Hr = Left(Me.Tm, 2) 'Hours
X = InStr(1, Hr, ":")
Mn = Mid(Me.Tm, 4, 2) 'Minutes
Sc = Mid(Me.Tm, 7, 2) ' Seconds for actual Seconds


If X = 2 Then
Hr = Left(Hr, 1)
Mn = Mid(Me.Tm, 3, 2)
Sc = Mid(Me.Tm, 6, 2)
End If

Sc = "00" 'Remark this out if you want actual seconds

Select Case Mn
Case 0 To 7 'Min
Mn = 0
Case 8 To 27
Mn = 15
Case 28 To 37
Mn = 30
Case 38 To 47
Mn = 45
Case 48 To 59
Mn = 0
End Select

MyTime = TimeSerial(Hr, Mn, Sc) ' MyTime
MsgBox MyTime 'Message box to display time

'=====================================================
'End of code





HTH

Regards

Sam

Australia
 
Back
Top