more buttons

D

DaveB

Below is my VB. I'm have trouble with the last button.
I'm trying to get it to subtract commad91 from command 92
and come up with hours and minutes. the problem is that
unless I put a 0 in front of :00 it will not tell me the
minutes, but when I put it 0:00 it reads 290:12 for 29
hours and 12 minutes.

Option Compare Database

Private Sub Command91_Click()
Me!DateTime1stContact = now()
End Sub

Private Sub Command92_Click()
StartDateTime = Date + Time()
End Sub
Private Sub Command93_Click()
Me!CompletionDateTime = now()
End Sub

Private Sub Command95_Click()
Me!TotalTimetoBill = DateDiff("h", Me!StartDateTime, Me!
CompletionDateTime) & Format(DateDiff("n", Me!
StartDateTime, Me!CompletionDateTime) Mod 60, "0:00")
End Sub
 
J

John Vinson

Private Sub Command95_Click()
Me!TotalTimetoBill = DateDiff("h", Me!StartDateTime, Me!
CompletionDateTime) & Format(DateDiff("n", Me!
StartDateTime, Me!CompletionDateTime) Mod 60, "0:00")
End Sub

Use the Format function on DateDiff as well. Actually let's simplify
the code a bit:

Private Sub Command95_Click() ' PLEASE PLEASE for your own sanity,
' rename these buttons!!!!!!!
Dim lngElapsed As Long
Dim strElapsed As Long
' Calculate the time elapsed in minutes
lngElapsed = DateDiff("n", Me!StartDateTime, Me!CompletionDateTime)
' Express this time in hh:nn format
' Integer divide by 60 to get hours, express as two digits with
' leading zero using the Format function
strElapsed = Format(lngElapsed \ 60, "00")
' Now take the remainder after dividing by 60 and format as minutes
strElapsed = strElapsed & Format(lngElapsed MOD 60, ":00")
Me!TotalTimeToBill = strElapsed
End Sub


Or, without the educational verbiage,

Private Sub Command95_Click()
Dim lngElapsed As Long
lngElapsed = DateDiff("n", Me!StartDateTime, Me!CompletionDateTime)
Me!TotalTimeToBill = Format(lngElapsed \ 60, "00") _
& Format(lngElapsed MOD 60, ":00")
End Sub
 

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