RE: Timer updated on form
- From: Klatuu <Klatuu@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 14 Sep 2005 06:15:03 -0700
"Rod" wrote:
> OK, a few question about your code:
> 1) I copied the code and received the error: "Ambiguous name
> detected:Form_Timer
This is because you have 2 Form_Timer events in you code.
> 2) What is Command27.Caption?
Command27 is the name of the command button that starts and ends call
timeing. For you , it would be your Dial command button. You just need to
change the names. Also notice that I wrote it so the user can stop the call
without moving off the record so they can do any additional data entry needed
after they hang up.
> 3) What is blnKeepingTime
This is a boolean (Yes/No) data type variable used to know whether to update
the time display. Since we need to keep the timer running while the form is
open, we have to know how to handle it. If blnKeepingTime is = True, a call
is in progress and we update the time display; otherwise, we do not.
> 4) I noticed you have two: Private Sub Form_Timer()
Reviewing my post, I don't see two Private Sub From_Timer() events. Maybe
you copied it in twice. This is why you are getting the ambiguous name error
> I'm just trying to understand what you have done so I can adapt my form to
> fit your code.
See below for detailed explanations.
>
> Thanks much for your help.
>
> "Klatuu" wrote:
>
> > Rod,
> > As I promised, I looked at this over the weekend, and here is what I came up
> > with. Since I did not take the original code home with me, this doesn't look
> > much like the original posting.
> > What I have done is created 2 module level variables, one to keep track of
> > whether a call is in place and one to display the call time.
> > I also made a modification to the Dial command button so that if the Caption
> > is "Dial", it zeros the timer, sets blnKeepingTime to True, and changes the
> > caption to "Hang Up". I think you will find this useful to the users so they
> > can stop the call when they need to. It also prevents them from restarting
> > the call which would reset the timer. This code also causes the call textbox
> > to flase red/white when it reaches 3 minutes. There is also code in the
> > Current event that reset the time and turns time keeping off in preparation
> > for the next call
> >
> > Private blnKeepingTime As Boolean 'Determines if a call is in place
> > Private dtmCallTime As Date 'Used by the timer to display call time
> >
***********************************************
New Answers Start Here
This sub fires when you click on the Dial command button. Change the names
to suit your form.
> > Private Sub Command27_Click()
Here we use the button's caption (what displays on the form) to determine
whether a call is in progress. If it says Dail, then we start a call.
> > If Me.Command27.Caption = "Dial" Then
You will need to add you code to do the dialing and whater else you need to do
> > Me.Command27.Caption = "Hang UP"
Changes the caption so the next click will stop the call
> > blnKeepingTime = True
This variable will tell the Timer event to update the time display
> > dtmCallTime = TimeSerial(0, 0, 0)
Initializes the call time variable to 0. See the TimeSerial function in VBA
Help for more info
> > Me.Text9.BackColor = RGB(255, 255, 255)
Sets the background color of the time display text box to white
> > Me.Text9 = Format(dtmCallTime, "nn:ss")
Displays the call time variable in the time display text box formatted to
display minutes and seconds
> > Else
These are the activites for enting a call
> > Me.Text9.BackColor = RGB(255, 255, 255)
Sets the background color of the time display text box to white
> > Me.Command27.Caption = "Dial"
Changes the caption to Dial so the next click starts a call
> > blnKeepingTime = False
Tells the timer event to ignore updating the time
> > End If
> > End Sub
> >
This event fires when you move to another record
> > Private Sub Form_Current()
> > Me.Command27.Caption = "Dial"
Prepares for starting a new call
> > blnKeepingTime = False
Tells the timer event to ignore updating the time
> > dtmCallTime = TimeSerial(0, 0, 0)
Initializes the call timer variable to 0
> > Me.Text9.BackColor = RGB(255, 255, 255)
Sets the time display background color to white
> > Me.Text9 = Format(dtmCallTime, "nn:ss")
Displays the call time in minutes and seconds
> > End Sub
> >
Fires when you load the form
> > Private Sub Form_Load()
> > Me.TimerInterval = 1000
Sets the timer for the form to 1 second
> > End Sub
> >
Fires every second
> > Private Sub Form_Timer()
> > If blnKeepingTime Then
A call is in progress
> > dtmCallTime = DateAdd("s", 1, dtmCallTime)
Adds 1 second to the time keeping variable
> > Me.Text9 = Format(dtmCallTime, "nn:ss")
Displays the updated time
> > If Minute(dtmCallTime) >= 3 Then
The call is now at least 3 minutes in duration
This If statement causes the time display to flash red and white. Because
we are doing it every time the timer event fires, it will change colors every
second
> > If Me.Text9.BackColor = RGB(255, 255, 255) Then
> > Me.Text9.BackColor = RGB(255, 0, 0)
> > Else
> > Me.Text9.BackColor = RGB(255, 255, 255)
> > End If
> > End If
> > End If
> > End Sub
> >
> >
> > "Rod" wrote:
> >
> > > No problem. I have learned a lot working with you. Anxiously awaiting your
> > > reply...
> > >
> > > "Klatuu" wrote:
> > >
> > > > Rod,
> > > > I forgot something important. Access Help says to set the timer interval in
> > > > the Load event of the form. Since it is not resetting and running correctly,
> > > > I will need to play with it and trick it. I know I can do it, I did it
> > > > several years ago, but I don't remember exactly how. I will play with it
> > > > over the weekend, and get back to you.
> > > >
> > > > My apologies for wasting your time chasing this problem. Once I get all the
> > > > egg off my face, I will get it fixed and get back to you.
> > > >
> > > > "Rod" wrote:
> > > >
> > > > > The clock is running from zero. It starts when I move to the next record
> > > > > regardless if I press the dial button. It needs to only start when I press
> > > > > the button. I have the code in the right location, but something is kicking
> > > > > it off regardless. Pressing the dial button does not even reset the clock -
> > > > > something os overriding the dial button statement to start the clock.
> > > > >
> > > > > "Klatuu" wrote:
> > > > >
> > > > > > In the current event, you are setting the timer interval to 1 second. You
> > > > > > need to set it to 0. Then you set it to 1000 in the Button Click event to
> > > > > > start it.
> > > > > >
> > > > > > "Rod" wrote:
> > > > > >
> > > > > > > It resets the clock, but the clock starts without me pressing the dial button
> > > > > > > when I advance the record. Here is a copy of what I have and where the key
> > > > > > > components are in the editor:
> > > > > > >
> > > > > > > Option Compare Database
> > > > > > > Private dtmCallTime As Date ' Form Level variable
> > > > > > > Private Sub Form_Timer()
> > > > > > > Dim dtmTimeCheck As Date
> > > > > > >
> > > > > > > dtmTimeCheck = TimeSerial(0, 3, 0)
> > > > > > > dtmCallTime = DateAdd("s", 1, dtmCallTime)
> > > > > > > Me.txtCallDuration = Format(dtmCallTime, "nn:ss")
> > > > > > > If dtmCallTime >= dtimTimeCheck Then
> > > > > > > Me.txtCallDuration.BackColor = _
> > > > > > > IIf(Me.txtCallDuration.BackColor = RGB(255, 0, 0), _
> > > > > > > RGB(255, 255, 255), RGB(255, 0, 0))
> > > > > > > End If
> > > > > > >
> > > > > > > End Sub
> > > > > > >
> > > > > > > Private Sub Form_Current()
> > > > > > > 'next record. This will reset the clock.
> > > > > > > dtmCallTime = TimeSerial(0, 0, 0)
> > > > > > > Me.TimerInterval = 1000 ' Sets interval to 1 second.
> > > > > > >
> > > > > > > End Sub
> > > > > > >
> > > > > > > Private Sub btnDialNumber_Click()
> > > > > > > On Error GoTo Err_btnDialNumber_Click
> > > > > > >
> > > > > > > Dim stDialStr As String
> > > > > > > Dim PrevCtl As Control
> > > > > > > Const ERR_OBJNOTEXIST = 2467
> > > > > > > Const ERR_OBJNOTSET = 91
> > > > > > > Const ERR_CANTMOVE = 2483
> > > > > > >
> > > > > > > Set PrevCtl = Screen.PreviousControl
> > > > > > >
> > > > > > > Me.Text131 = DLookup("[Msg]", "tblScripts", "[ID] = " & Me.Frame124)
> > > > > > > CALLED_ON = Date
> > > > > > > CALL_RESULTS = "Message"
> > > > > > >
> > > > > > > Me.tbxMsgToday = Nz(DCount([CALLED_ON], "tblCandidates", "[CALLED_ON] =
> > > > > > > " & Format(Date, "\#mm\/dd\/yyyy\#") & " And [CALL_RESULTS] = 'Message'"), 0)
> > > > > > > Me.tbxCallsToday = Nz(DCount([CALLED_ON], "tblCandidates", "[CALLED_ON]
> > > > > > > = " & Format(Date, "\#mm\/dd\/yyyy\#")), 0)
> > > > > > >
> > > > > > > Select Case [RESUME]
> > > > > > > Case -1
> > > > > > > Frame124 = 1
> > > > > > > Case 0
> > > > > > > Frame124 = 8
> > > > > > > End Select
> > > > > > >
> > > > > > > Application.Run "utility.wlib_AutoDial", tbxDIALNUMBER
> > > > > > >
> > > > > > > Exit_btnDialNumber_Click:
> > > > > > > Exit Sub
> > > > > > >
> > > > > > > Err_btnDialNumber_Click:
> > > > > > > If (Err = ERR_OBJNOTEXIST) Or (Err = ERR_OBJNOTSET) Or (Err =
> > > > > > > ERR_CANTMOVE) Then
> > > > > > > Resume Next
> > > > > > > End If
> > > > > > > MsgBox Err.Description
> > > > > > > Resume Exit_btnDialNumber_Click
> > > > > > >
> > > > > > > End Sub
> > > > > > >
> > > > > > >
> > > > > > > "Klatuu" wrote:
> > > > > > >
> > > > > > > > Glad to hear it is working. It was totally untested.
> > > > > > > > Put that code in the Current event of the form.
> > > > > > > >
> > > > > > > > "Rod" wrote:
> > > > > > > >
> > > > > > > > > Your code is working well.
> > > > > > > > > The call is complete when the person goes to the next record. How can I
> > > > > > > > > place your "Call Complete" code so it appears when the user moves to the next
> > > > > > > > > record, i.e. open next record or leave current record? They move to the next
> > > > > > > > > record by using the next record arrow in the bottom left of the frame.
> > > > > > > > >
> > > > > > > > > "Klatuu" wrote:
> > > > > > > > >
> > > > > > > > > > Private dtmCallTime as Date ' Form Level variable
> > > > > > > > > >
> > > > > > > > > > In the Click event of the DailButton:
> > > > > > > > > >
> > > > > > > > > > dtmCallTime = timeserial(0,0,0)
> > > > > > > > > > Me.TimerInterval = 1000 ' Sets interval to 1 second.
> > > > > > > > > >
> > > > > > > > > > In the Timer event of the form
> > > > > > > > > >
> > > > > > > > > > Private Sub Form_Timer()
> > > > > > > > > > Dim dtmTimeCheck as Date
> > > > > > > > > >
> > > > > > > > > > dtmTimeCheck = TimeSerial(0,3,0)
> > > > > > > > > > dtmCallTime = DateAdd("s",1,dtmCallTime)
> > > > > > > > > > Me.txtCall Duration = Format(dtmCallTime, "nn:ss")
> > > > > > > > > > If dtmCallTime >= dtimTimeCheck Then
> > > > > > > > > > Me.txtCallDuration.BackColor = _
> > > > > > > > > > Iif(Me.txtCallDuration.BackColor = RGB(255, 0, 0), _
> > > > > > > > > > RGB(255, 255, 255), RGB(255, 0, 0))
> > > > > > > > > > End If
> > > > > > > > > >
> > > > > > > > > > End Sub
> > > > > > > > > >
> > > > > > > > > > You will also need to reset everything after a call is complete. Put this
> > > > > > > > > > right after you complete the call:
> > > > > > > > > >
> > > > > > > > > > Me.txtCallDuration.BackColor = RGB(255,255,255)
> > > > > > > > > > Me.TimerInterval = 0
> > > > > > > > > > "Rod" wrote:
> > > > > > > > > >
> > > > > > > > > > > I create:
> > > > > > > > > > > tbxCallTimer = 0
> > > > > > > > > > > Me.tbxCallTimer = Timer
> > > > > > > > > > >
> > > > > > > > > > > How do I update this every second?
> > > > > > > > > > > I tried the property format of nn:ss, but that did not give me 02:12 for 2
> > > > > > > > > > > minutes 12 seconds as Ihad hoped.
> > > > > > > > > > >
> > > > > > > > > > > "Klatuu" wrote:
> > > > > > > > > > >
> > > > > > > > > > > > Here is a basic concept.
> > > > > > > > > > > > In the Click event of DialButton set the value of the Call Timer text box to
> > > > > > > > > > > > 00:00 and start a timer event that will update the Timer text box every
> > > > > > > > > > > > second. And in the Change event of the Call Timer text box, change the back
> > > > > > > > > > > > color when it's value is = "00:00"
> > > > > > > > > > > >
> > > > > > > > > > > > "Rod" wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > > A2003
> > > > > > > > > > > > > I have people who loose track of how long they are on a call.
> > > > > > > > > > > > >
> > > > > > > > > > > > > 1) They would like to have a timer on the form showing how long it has been
> > > > > > > > > > > > > since the user pressed the DialButton - counting up the min:sec would be
> > > > > > > > > > > > > fine.
> > > > > > > > > > > > > 2) If time is greater than 3 minutes they would like the color of min:sec to
> > > > > > > > > > > > > change to red.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Thanks
.
- Follow-Ups:
- RE: Timer updated on form
- From: Rod
- RE: Timer updated on form
- References:
- Timer updated on form
- From: Rod
- RE: Timer updated on form
- From: Klatuu
- RE: Timer updated on form
- From: Rod
- RE: Timer updated on form
- From: Klatuu
- RE: Timer updated on form
- From: Rod
- RE: Timer updated on form
- From: Klatuu
- RE: Timer updated on form
- From: Rod
- RE: Timer updated on form
- From: Klatuu
- RE: Timer updated on form
- From: Rod
- RE: Timer updated on form
- From: Klatuu
- RE: Timer updated on form
- From: Rod
- RE: Timer updated on form
- From: Klatuu
- RE: Timer updated on form
- From: Rod
- Timer updated on form
- Prev by Date: Re: REPOST: Opening a subsequent form from another with filtered c
- Next by Date: Re: preview/print execution results in database close-down
- Previous by thread: RE: Timer updated on form
- Next by thread: RE: Timer updated on form
- Index(es):