Command Button Help


kbSU89

New Member
Need some programming help

I have a database that I want to put a command button on to track the length of time a person stays on the phone

Example: When the phone rings I want the person to click on a start button and it starts calculating the time, when the person finishes I want them to click on the end button.

The database is in Access, I searched online but I could not find anything similiar to what I am trying to do.

If anyone understands, help me out...Thanks
 

Yes,

I am using Access Forms. All the information is on the form when the first call comes in, so I want them to track the total length of the call
 
I think the easiest way to do this would be to have a table that would have a field for the start time and the end time in addition with the primary key. You can have two buttons (one of them will insert the start time and the other will insert the end time and calculate the difference between the two). Then you can display the difference in (in minutes or whatever) on a texbox or a message box (msgbox).

Since I am not familar with access forms, I am not sure how you would do this through the syntax though.
 
Create a command button

In the OnClick event, you will want to capture the start time and once the button is clicked again, capture the end time. (end time - start time) should get you the time on the phone. However, this is totally dependent on the user clicking the button. Or use 2 buttons, one being the start and the other being the end.
 
Da_Sperm said:
Create a command button

In the OnClick event, you will want to capture the start time and once the button is clicked again, capture the end time. (end time - start time) should get you the time on the phone. However, this is totally dependent on the user clicking the button. Or use 2 buttons, one being the start and the other being the end.

Thanks Sperm

I did a search on Microsoft and did not find this info.

Thanks again
 
Da_Sperm said:
Create a command button

In the OnClick event, you will want to capture the start time and once the button is clicked again, capture the end time. (end time - start time) should get you the time on the phone. However, this is totally dependent on the user clicking the button. Or use 2 buttons, one being the start and the other being the end.


Sperm

Once I create the command button and go to the event procedure, what code would I use to calculate the time?
 
89comSUgrad said:
Sperm

Once I create the command button and go to the event procedure, what code would I use to calculate the time?

VBScript References

I would probably use the 'TIMER' function. It returns the # of seconds that have elapsed since midnight. EXAMPLE

Dim PauseTime StartTime, FinishTime, TotalTime
PauseTime = 5 ' Set duration.
StartTime = Timer ' Set start time.
Do While Timer < StartTime + PauseTime
DoEvents ' Yield to other processes.​
Loop
FinishTime = Timer ' Set end time.
TotalTime = Finish - Start ' Calculate total time.
MsgBox "Paused for " & TotalTime & " seconds"


This code will capture the StartTime, then 5 seconds later capture the EndTime (both times are # of secs since midnight). The FinalTime is the diff between StartTime and FinishedTIme. You would have to do additional calculations to convert the seconds into minutes or hours by simply dividing Finished time by 60.
 
I found this code and it works. Still need it to move the time for each call to save.

Thanks again for your help

Option Compare Database
Option Explicit

Dim TotalElapsedMilliSec As Long
Dim StartTickCount As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long


Private Sub cmdStartStop_Click()
If Me.TimerInterval = 0 Then
StartTickCount = GetTickCount()
Me.TimerInterval = 15
Me!cmdStartStop.Caption = "&STOP"
Me.cmdStartStop.ForeColor = RGB(255, 0, 0)
Me.cmdStartStop.FontSize = "12"
Me!cmdReset.Enabled = False
Else
TotalElapsedMilliSec = TotalElapsedMilliSec + (GetTickCount() - StartTickCount)
Me.TimerInterval = 0
Me!cmdStartStop.Caption = "Start the &Timer"
Me.cmdStartStop.ForeColor = RGB(0, 64, 128)
Me.cmdStartStop.FontSize = "8"
Me!cmdReset.Enabled = True
End If
End Sub

Private Sub cmdClose_Click()
DoCmd.Close acForm, "frmStopWatch", acSaveNo
End Sub

Private Sub Form_Timer()
Dim Hours As String
Dim Minutes As String
Dim Seconds As String
Dim MilliSec As String
Dim Msg As String
Dim ElapsedMilliSec As Long

ElapsedMilliSec = (GetTickCount() - StartTickCount) + TotalElapsedMilliSec

Hours = Format((ElapsedMilliSec \ 3600000), "00")
Minutes = Format((ElapsedMilliSec \ 60000) Mod 60, "00")
Seconds = Format((ElapsedMilliSec \ 1000) Mod 60, "00")
MilliSec = Format((ElapsedMilliSec Mod 1000) \ 10, "00")

Me!ElapsedTime = Hours & ":" & Minutes & ":" & Seconds & ":" & MilliSec

End Sub

Private Sub cmdReset_Click()
TotalElapsedMilliSec = 0
Me!ElapsedTime = "00:00:00:00"
End Sub
 
Back
Top