 |
|
 |
|
Next: Me.Name is name of form. Is there a generic way t..
|
| Author |
Message |
External

Since: May 12, 2008 Posts: 47
|
(Msg. 1) Posted: Fri Nov 21, 2008 1:12 pm
Post subject: Timer Code Archived from groups: microsoft>public>access (more info?)
|
|
|
Hi,
With help from various.....
I have a form with various timers on it which currently only works in
minutes & seconds. I have the following code in my on timer event, however i
want my timers to be able to run into hours as well as the minutes & seconds
- any suggestions what changes i need to make to the following code in order
to do this:
Private Sub Form_Timer()
If DateDiff("s", Now, dteStartTime) < 0 Then
Me.Text4 = "Check Required"
Me.Text4.BackColor = vbRed
varCounter = "00:0" & Int(DateDiff("s", dteStartTime, Now) / 60)
varCounter = varCounter & ":" _
& Right("0" & DateDiff("s", dteStartTime, Now) Mod 60, 2)
Me.Timer2 = varCounter
Else
varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime) / 60)
varCounter = varCounter & ":" _
& Right("0" & DateDiff("s", Now, dteStartTime) Mod 60, 2)
Me.Timer1 = varCounter
End If
End Sub
Thanks for any help! >> Stay informed about: Timer Code |
|
| Back to top |
|
 |  |
External

Since: Sep 14, 2006 Posts: 55
|
(Msg. 2) Posted: Fri Nov 21, 2008 2:34 pm
Post subject: RE: Timer Code [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
I responded to the previous thread today but I guess you didn't see it.
Here is a simpler, more effective method that should do everything
you want;
Private Sub Form_Timer()
If DateDiff("s", Now, dteStartTime) < 0 Then
Me.Text4 = "Check Required"
Me.Text4.BackColor = vbRed
Me.Timer2 = Time - TimeValue(dteStartTime)
Else
Me.Timer1 = Time - TimeValue(dteStartTime)
End If
End Sub
--
_________
Sean Bailey
"Nick T" wrote:
> Hi,
> With help from various.....
> I have a form with various timers on it which currently only works in
> minutes & seconds. I have the following code in my on timer event, however i
> want my timers to be able to run into hours as well as the minutes & seconds
> - any suggestions what changes i need to make to the following code in order
> to do this:
>
>
> Private Sub Form_Timer()
>
> If DateDiff("s", Now, dteStartTime) < 0 Then
> Me.Text4 = "Check Required"
> Me.Text4.BackColor = vbRed
> varCounter = "00:0" & Int(DateDiff("s", dteStartTime, Now) / 60)
> varCounter = varCounter & ":" _
> & Right("0" & DateDiff("s", dteStartTime, Now) Mod 60, 2)
> Me.Timer2 = varCounter
> Else
> varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime) / 60)
> varCounter = varCounter & ":" _
> & Right("0" & DateDiff("s", Now, dteStartTime) Mod 60, 2)
> Me.Timer1 = varCounter
> End If
>
> End Sub
>
>
>
> Thanks for any help!
> >> Stay informed about: Timer Code |
|
| Back to top |
|
 |  |
External

Since: May 12, 2008 Posts: 47
|
(Msg. 3) Posted: Fri Nov 21, 2008 2:59 pm
Post subject: RE: Timer Code [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Hi,
Think i may be biting off more than i can chew here!
Its getting a bit complicated (to me) but ill explain in the hope that you
may be able to help.
Ok, so i originally started with 2 timers - one timer1 which would count
down - on zero it would change the colour of my text box, and then timer 2
would start counting up. When a user clicks a specific cmd button it resets
timer 1 to start counting down again from a pre programmed amount ie. 2hours,
and resets the backcolour of my text box.
Now, i want to replicate this on the same form, but have 4 timers. Each one
needs to work independantly. The code you gave me worked really well,
however iv been playing to try & modify it to account for another 2 timers,
however not with much success.
Iv posted the code below which i have been playing with, in the hope that
you may be able to see where i am wanting to go with this.......(hope it
makes sence) but as i said - not having much luck. If you can help great but
let me know if i need to explain my need better:
Private Sub Form_Timer()
If DateDiff("s", Now, dteStartTime) < 0 Then
Me.Text4 = "Check Required"
Me.Text4.BackColor = vbRed
Me.Overdueby.Visible = True
Me.LastInspectionOverDueBy.Visible = False
Me.Text5 = "Check Required"
Me.Text5.BackColor = vbRed
Me.OverduebyWt.Visible = True
Me.LastInspectionOverDueByWt.Visible = False
varCounter = "00:0" & Int(DateDiff("s", dteStartTime, Now) / 60)
varCounter = varCounter & ":" _
& Right("0" & DateDiff("s", dteStartTime, Now) Mod 60, 2)
Me.Timer2 = varCounter
varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime) / 60)
varCounter = varCounter & ":" _
& Right("0" & DateDiff("s", Now, dteStartTime) Mod 60, 2)
Me.Timer4 = varCounter
Else
varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime) / 60)
varCounter = varCounter & ":" _
& Right("0" & DateDiff("s", Now, dteStartTime) Mod 60, 2)
Me.Timer1 = varCounter
varCounter = "00:0" & Int(DateDiff("s", dteStartTime, Now) / 60)
varCounter = varCounter & ":" _
& Right("0" & DateDiff("s", dteStartTime, Now) Mod 60, 2)
Me.Timer3 = varCounter
End If
End Sub
"Beetle" wrote:
> I responded to the previous thread today but I guess you didn't see it.
>
> Here is a simpler, more effective method that should do everything
> you want;
>
> Private Sub Form_Timer()
>
> If DateDiff("s", Now, dteStartTime) < 0 Then
> Me.Text4 = "Check Required"
> Me.Text4.BackColor = vbRed
> Me.Timer2 = Time - TimeValue(dteStartTime)
> Else
> Me.Timer1 = Time - TimeValue(dteStartTime)
> End If
>
> End Sub
>
> --
> _________
>
> Sean Bailey
>
>
> "Nick T" wrote:
>
> > Hi,
> > With help from various.....
> > I have a form with various timers on it which currently only works in
> > minutes & seconds. I have the following code in my on timer event, however i
> > want my timers to be able to run into hours as well as the minutes & seconds
> > - any suggestions what changes i need to make to the following code in order
> > to do this:
> >
> >
> > Private Sub Form_Timer()
> >
> > If DateDiff("s", Now, dteStartTime) < 0 Then
> > Me.Text4 = "Check Required"
> > Me.Text4.BackColor = vbRed
> > varCounter = "00:0" & Int(DateDiff("s", dteStartTime, Now) / 60)
> > varCounter = varCounter & ":" _
> > & Right("0" & DateDiff("s", dteStartTime, Now) Mod 60, 2)
> > Me.Timer2 = varCounter
> > Else
> > varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime) / 60)
> > varCounter = varCounter & ":" _
> > & Right("0" & DateDiff("s", Now, dteStartTime) Mod 60, 2)
> > Me.Timer1 = varCounter
> > End If
> >
> > End Sub
> >
> >
> >
> > Thanks for any help!
> > >> Stay informed about: Timer Code |
|
| Back to top |
|
 |  |
External

Since: Sep 14, 2006 Posts: 55
|
(Msg. 4) Posted: Fri Nov 21, 2008 3:33 pm
Post subject: RE: Timer Code [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
That won't work because you are asking the variable varCounter to
do two different things at the same time.
Under what conditions are Timer3 and Timer4 supposed to start/stop,
and are they supposed to count up or down?
--
_________
Sean Bailey
"Nick T" wrote:
> Hi,
> Think i may be biting off more than i can chew here!
> Its getting a bit complicated (to me) but ill explain in the hope that you
> may be able to help.
>
> Ok, so i originally started with 2 timers - one timer1 which would count
> down - on zero it would change the colour of my text box, and then timer 2
> would start counting up. When a user clicks a specific cmd button it resets
> timer 1 to start counting down again from a pre programmed amount ie. 2hours,
> and resets the backcolour of my text box.
> Now, i want to replicate this on the same form, but have 4 timers. Each one
> needs to work independantly. The code you gave me worked really well,
> however iv been playing to try & modify it to account for another 2 timers,
> however not with much success.
>
> Iv posted the code below which i have been playing with, in the hope that
> you may be able to see where i am wanting to go with this.......(hope it
> makes sence) but as i said - not having much luck. If you can help great but
> let me know if i need to explain my need better:
>
> Private Sub Form_Timer()
>
> If DateDiff("s", Now, dteStartTime) < 0 Then
> Me.Text4 = "Check Required"
> Me.Text4.BackColor = vbRed
> Me.Overdueby.Visible = True
> Me.LastInspectionOverDueBy.Visible = False
> Me.Text5 = "Check Required"
> Me.Text5.BackColor = vbRed
> Me.OverduebyWt.Visible = True
> Me.LastInspectionOverDueByWt.Visible = False
>
>
>
> varCounter = "00:0" & Int(DateDiff("s", dteStartTime, Now) / 60)
> varCounter = varCounter & ":" _
> & Right("0" & DateDiff("s", dteStartTime, Now) Mod 60, 2)
> Me.Timer2 = varCounter
>
> varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime) / 60)
> varCounter = varCounter & ":" _
> & Right("0" & DateDiff("s", Now, dteStartTime) Mod 60, 2)
> Me.Timer4 = varCounter
>
>
> Else
> varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime) / 60)
> varCounter = varCounter & ":" _
> & Right("0" & DateDiff("s", Now, dteStartTime) Mod 60, 2)
> Me.Timer1 = varCounter
>
> varCounter = "00:0" & Int(DateDiff("s", dteStartTime, Now) / 60)
> varCounter = varCounter & ":" _
> & Right("0" & DateDiff("s", dteStartTime, Now) Mod 60, 2)
> Me.Timer3 = varCounter
>
>
>
>
> End If
>
>
> End Sub
>
>
> "Beetle" wrote:
>
> > I responded to the previous thread today but I guess you didn't see it.
> >
> > Here is a simpler, more effective method that should do everything
> > you want;
> >
> > Private Sub Form_Timer()
> >
> > If DateDiff("s", Now, dteStartTime) < 0 Then
> > Me.Text4 = "Check Required"
> > Me.Text4.BackColor = vbRed
> > Me.Timer2 = Time - TimeValue(dteStartTime)
> > Else
> > Me.Timer1 = Time - TimeValue(dteStartTime)
> > End If
> >
> > End Sub
> >
> > --
> > _________
> >
> > Sean Bailey
> >
> >
> > "Nick T" wrote:
> >
> > > Hi,
> > > With help from various.....
> > > I have a form with various timers on it which currently only works in
> > > minutes & seconds. I have the following code in my on timer event, however i
> > > want my timers to be able to run into hours as well as the minutes & seconds
> > > - any suggestions what changes i need to make to the following code in order
> > > to do this:
> > >
> > >
> > > Private Sub Form_Timer()
> > >
> > > If DateDiff("s", Now, dteStartTime) < 0 Then
> > > Me.Text4 = "Check Required"
> > > Me.Text4.BackColor = vbRed
> > > varCounter = "00:0" & Int(DateDiff("s", dteStartTime, Now) / 60)
> > > varCounter = varCounter & ":" _
> > > & Right("0" & DateDiff("s", dteStartTime, Now) Mod 60, 2)
> > > Me.Timer2 = varCounter
> > > Else
> > > varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime) / 60)
> > > varCounter = varCounter & ":" _
> > > & Right("0" & DateDiff("s", Now, dteStartTime) Mod 60, 2)
> > > Me.Timer1 = varCounter
> > > End If
> > >
> > > End Sub
> > >
> > >
> > >
> > > Thanks for any help!
> > > >> Stay informed about: Timer Code |
|
| Back to top |
|
 |  |
External

Since: May 12, 2008 Posts: 47
|
(Msg. 5) Posted: Fri Nov 21, 2008 3:57 pm
Post subject: RE: Timer Code [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Hi.... (thanks for reading all that) i know posts are supposed to be kept
brief!
Anyway, iv solved it - finally got there, however you may be able to tell me
if what iv done is against 'access rules' as far as good practice is
concerned:
So,
in my form code i put this in the top part:
Option Compare Database
Option Explicit
Dim dteStartTime1 As Date
Dim dteStartTime2 As Date - (this line i added)
Dim varCounter As Variant
Then in my on timer code i put this:
Private Sub Form_Timer()
If DateDiff("s", Now, dteStartTime1) < 0 Then
Me.Text4 = "Check Required"
Me.Text4.BackColor = vbRed
Me.Overdueby.Visible = True
Me.LastInspectionOverDueBy.Visible = False
varCounter = "00:0" & Int(DateDiff("s", dteStartTime1, Now) / 60)
varCounter = varCounter & ":" _
& Right("0" & DateDiff("s", dteStartTime1, Now) Mod 60, 2)
Me.Timer2 = varCounter
Else
varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime1) / 60)
varCounter = varCounter & ":" _
& Right("0" & DateDiff("s", Now, dteStartTime1) Mod 60, 2)
Me.Timer1 = varCounter
End If
If DateDiff("s", Now, dteStartTime2) < 0 Then
Me.Text5 = "Check Required"
Me.Text5.BackColor = vbRed
Me.OverduebyWt.Visible = True
Me.LastInspectionOverDueByWt.Visible = False
varCounter = "00:0" & Int(DateDiff("s", dteStartTime2, Now) / 60)
varCounter = varCounter & ":" _
& Right("0" & DateDiff("s", dteStartTime2, Now) Mod 60, 2)
Me.Timer4 = varCounter
Else
varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime2) / 60)
varCounter = varCounter & ":" _
& Right("0" & DateDiff("s", Now, dteStartTime2) Mod 60, 2)
Me.Timer3 = varCounter
End If
End Sub
Iv still got a bit of 'tidying' to do on it, but in principle i think its
working, however i still seem to have a problem with getting 'hours' on the
timers. ie if i want it to count down from 2hrs i would put in 7200 however
this comes out as 00:0119:59 and starts counting down. As i said, i have a
cmd button which when clicked, resets my timer - for info, this is my code in
that:
Private Sub FPCheck_Click()
On Error GoTo Err_FPCheck_Click
dteStartTime1 = DateAdd("s", 7200, Now())
Me.TimerInterval = 1000
Me.Text4 = ""
Me.Text4.BackColor = vbWhite
Me.Overdueby.Visible = False
Me.LastInspectionOverDueBy.Visible = True
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "FPCheckForm"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_FPCheck_Click:
Exit Sub
Err_FPCheck_Click:
MsgBox Err.Description
Resume Exit_FPCheck_Click
End Sub
Hope to hear back from you - your helps been great!
Thanks
"Beetle" wrote:
> That won't work because you are asking the variable varCounter to
> do two different things at the same time.
>
> Under what conditions are Timer3 and Timer4 supposed to start/stop,
> and are they supposed to count up or down?
> --
> _________
>
> Sean Bailey
>
>
> "Nick T" wrote:
>
> > Hi,
> > Think i may be biting off more than i can chew here!
> > Its getting a bit complicated (to me) but ill explain in the hope that you
> > may be able to help.
> >
> > Ok, so i originally started with 2 timers - one timer1 which would count
> > down - on zero it would change the colour of my text box, and then timer 2
> > would start counting up. When a user clicks a specific cmd button it resets
> > timer 1 to start counting down again from a pre programmed amount ie. 2hours,
> > and resets the backcolour of my text box.
> > Now, i want to replicate this on the same form, but have 4 timers. Each one
> > needs to work independantly. The code you gave me worked really well,
> > however iv been playing to try & modify it to account for another 2 timers,
> > however not with much success.
> >
> > Iv posted the code below which i have been playing with, in the hope that
> > you may be able to see where i am wanting to go with this.......(hope it
> > makes sence) but as i said - not having much luck. If you can help great but
> > let me know if i need to explain my need better:
> >
> > Private Sub Form_Timer()
> >
> > If DateDiff("s", Now, dteStartTime) < 0 Then
> > Me.Text4 = "Check Required"
> > Me.Text4.BackColor = vbRed
> > Me.Overdueby.Visible = True
> > Me.LastInspectionOverDueBy.Visible = False
> > Me.Text5 = "Check Required"
> > Me.Text5.BackColor = vbRed
> > Me.OverduebyWt.Visible = True
> > Me.LastInspectionOverDueByWt.Visible = False
> >
> >
> >
> > varCounter = "00:0" & Int(DateDiff("s", dteStartTime, Now) / 60)
> > varCounter = varCounter & ":" _
> > & Right("0" & DateDiff("s", dteStartTime, Now) Mod 60, 2)
> > Me.Timer2 = varCounter
> >
> > varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime) / 60)
> > varCounter = varCounter & ":" _
> > & Right("0" & DateDiff("s", Now, dteStartTime) Mod 60, 2)
> > Me.Timer4 = varCounter
> >
> >
> > Else
> > varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime) / 60)
> > varCounter = varCounter & ":" _
> > & Right("0" & DateDiff("s", Now, dteStartTime) Mod 60, 2)
> > Me.Timer1 = varCounter
> >
> > varCounter = "00:0" & Int(DateDiff("s", dteStartTime, Now) / 60)
> > varCounter = varCounter & ":" _
> > & Right("0" & DateDiff("s", dteStartTime, Now) Mod 60, 2)
> > Me.Timer3 = varCounter
> >
> >
> >
> >
> > End If
> >
> >
> > End Sub
> >
> >
> > "Beetle" wrote:
> >
> > > I responded to the previous thread today but I guess you didn't see it.
> > >
> > > Here is a simpler, more effective method that should do everything
> > > you want;
> > >
> > > Private Sub Form_Timer()
> > >
> > > If DateDiff("s", Now, dteStartTime) < 0 Then
> > > Me.Text4 = "Check Required"
> > > Me.Text4.BackColor = vbRed
> > > Me.Timer2 = Time - TimeValue(dteStartTime)
> > > Else
> > > Me.Timer1 = Time - TimeValue(dteStartTime)
> > > End If
> > >
> > > End Sub
> > >
> > > --
> > > _________
> > >
> > > Sean Bailey
> > >
> > >
> > > "Nick T" wrote:
> > >
> > > > Hi,
> > > > With help from various.....
> > > > I have a form with various timers on it which currently only works in
> > > > minutes & seconds. I have the following code in my on timer event, however i
> > > > want my timers to be able to run into hours as well as the minutes & seconds
> > > > - any suggestions what changes i need to make to the following code in order
> > > > to do this:
> > > >
> > > >
> > > > Private Sub Form_Timer()
> > > >
> > > > If DateDiff("s", Now, dteStartTime) < 0 Then
> > > > Me.Text4 = "Check Required"
> > > > Me.Text4.BackColor = vbRed
> > > > varCounter = "00:0" & Int(DateDiff("s", dteStartTime, Now) / 60)
> > > > varCounter = varCounter & ":" _
> > > > & Right("0" & DateDiff("s", dteStartTime, Now) Mod 60, 2)
> > > > Me.Timer2 = varCounter
> > > > Else
> > > > varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime) / 60)
> > > > varCounter = varCounter & ":" _
> > > > & Right("0" & DateDiff("s", Now, dteStartTime) Mod 60, 2)
> > > > Me.Timer1 = varCounter
> > > > End If
> > > >
> > > > End Sub
> > > >
> > > >
> > > >
> > > > Thanks for any help!
> > > > >> Stay informed about: Timer Code |
|
| Back to top |
|
 |  |
External

Since: Nov 24, 2008 Posts: 1
|
(Msg. 6) Posted: Mon Nov 24, 2008 1:34 am
Post subject: Re: Timer Code [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
"Nick T" wrote in message
> Hi.... (thanks for reading all that) i know posts are supposed to be kept
> brief!
> Anyway, iv solved it - finally got there, however you may be able to tell
> me
> if what iv done is against 'access rules' as far as good practice is
> concerned:
>
> So,
> in my form code i put this in the top part:
>
> Option Compare Database
> Option Explicit
> Dim dteStartTime1 As Date
> Dim dteStartTime2 As Date - (this line i added)
> Dim varCounter As Variant
>
> Then in my on timer code i put this:
>
> Private Sub Form_Timer()
>
> If DateDiff("s", Now, dteStartTime1) < 0 Then
> Me.Text4 = "Check Required"
> Me.Text4.BackColor = vbRed
> Me.Overdueby.Visible = True
> Me.LastInspectionOverDueBy.Visible = False
>
>
>
> varCounter = "00:0" & Int(DateDiff("s", dteStartTime1, Now) /
> 60)
> varCounter = varCounter & ":" _
> & Right("0" & DateDiff("s", dteStartTime1, Now) Mod 60,
> 2)
> Me.Timer2 = varCounter
>
>
>
> Else
> varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime1) /
> 60)
> varCounter = varCounter & ":" _
> & Right("0" & DateDiff("s", Now, dteStartTime1) Mod 60,
> 2)
> Me.Timer1 = varCounter
>
> End If
>
>
> If DateDiff("s", Now, dteStartTime2) < 0 Then
> Me.Text5 = "Check Required"
> Me.Text5.BackColor = vbRed
> Me.OverduebyWt.Visible = True
> Me.LastInspectionOverDueByWt.Visible = False
>
>
>
> varCounter = "00:0" & Int(DateDiff("s", dteStartTime2, Now) /
> 60)
> varCounter = varCounter & ":" _
> & Right("0" & DateDiff("s", dteStartTime2, Now) Mod 60,
> 2)
> Me.Timer4 = varCounter
>
>
> Else
> varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime2) /
> 60)
> varCounter = varCounter & ":" _
> & Right("0" & DateDiff("s", Now, dteStartTime2) Mod 60,
> 2)
> Me.Timer3 = varCounter
>
> End If
>
> End Sub
>
>
> Iv still got a bit of 'tidying' to do on it, but in principle i think its
> working, however i still seem to have a problem with getting 'hours' on
> the
> timers. ie if i want it to count down from 2hrs i would put in 7200
> however
> this comes out as 00:0119:59 and starts counting down. As i said, i have
> a
> cmd button which when clicked, resets my timer - for info, this is my code
> in
> that:
>
> Private Sub FPCheck_Click()
> On Error GoTo Err_FPCheck_Click
>
> dteStartTime1 = DateAdd("s", 7200, Now())
> Me.TimerInterval = 1000
> Me.Text4 = ""
> Me.Text4.BackColor = vbWhite
> Me.Overdueby.Visible = False
> Me.LastInspectionOverDueBy.Visible = True
>
> Dim stDocName As String
> Dim stLinkCriteria As String
>
> stDocName = "FPCheckForm"
> DoCmd.OpenForm stDocName, , , stLinkCriteria
>
> Exit_FPCheck_Click:
> Exit Sub
>
> Err_FPCheck_Click:
> MsgBox Err.Description
> Resume Exit_FPCheck_Click
>
> End Sub
>
>
> Hope to hear back from you - your helps been great!
> Thanks
>
>
>
>
>
> "Beetle" wrote:
>
>> That won't work because you are asking the variable varCounter to
>> do two different things at the same time.
>>
>> Under what conditions are Timer3 and Timer4 supposed to start/stop,
>> and are they supposed to count up or down?
>> --
>> _________
>>
>> Sean Bailey
>>
>>
>> "Nick T" wrote:
>>
>> > Hi,
>> > Think i may be biting off more than i can chew here!
>> > Its getting a bit complicated (to m >> Stay informed about: Timer Code |
|
| Back to top |
|
 |  |
External

Since: Sep 14, 2006 Posts: 55
|
(Msg. 7) Posted: Mon Nov 24, 2008 9:55 am
Post subject: RE: Timer Code [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Try this;
Private Sub Form_Timer()
If DateDiff("s", Now, dteStartTime1) < 0 Then
Me.Text4 = "Check Required"
Me.Text4.BackColor = vbRed
Me.Overdueby.Visible = True
Me.LastInspectionOverDueBy.Visible = False
Me.Timer2 = Time - TimeValue(dteStartTime1)
Else
Me.Timer1 = Time - TimeValue(dteStartTime1)
End If
If DateDiff("s", Now, dteStartTime2) < 0 Then
Me.Text5 = "Check Required"
Me.Text5.BackColor = vbRed
Me.OverduebyWt.Visible = True
Me.LastInspectionOverDueByWt.Visible = False
Me.Timer4 = Time - TimeValue(dteStartTime2)
Else
Me.Timer3 = Time - TimeValue(dteStartTime2)
End If
End Sub
If the above works for you, then you can remove the varCounter variable
in the declarations section of your module.
--
_________
Sean Bailey
"Nick T" wrote:
> Hi.... (thanks for reading all that) i know posts are supposed to be kept
> brief!
> Anyway, iv solved it - finally got there, however you may be able to tell me
> if what iv done is against 'access rules' as far as good practice is
> concerned:
>
> So,
> in my form code i put this in the top part:
>
> Option Compare Database
> Option Explicit
> Dim dteStartTime1 As Date
> Dim dteStartTime2 As Date - (this line i added)
> Dim varCounter As Variant
>
> Then in my on timer code i put this:
>
> Private Sub Form_Timer()
>
> If DateDiff("s", Now, dteStartTime1) < 0 Then
> Me.Text4 = "Check Required"
> Me.Text4.BackColor = vbRed
> Me.Overdueby.Visible = True
> Me.LastInspectionOverDueBy.Visible = False
>
>
>
> varCounter = "00:0" & Int(DateDiff("s", dteStartTime1, Now) / 60)
> varCounter = varCounter & ":" _
> & Right("0" & DateDiff("s", dteStartTime1, Now) Mod 60, 2)
> Me.Timer2 = varCounter
>
>
>
> Else
> varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime1) / 60)
> varCounter = varCounter & ":" _
> & Right("0" & DateDiff("s", Now, dteStartTime1) Mod 60, 2)
> Me.Timer1 = varCounter
>
> End If
>
>
> If DateDiff("s", Now, dteStartTime2) < 0 Then
> Me.Text5 = "Check Required"
> Me.Text5.BackColor = vbRed
> Me.OverduebyWt.Visible = True
> Me.LastInspectionOverDueByWt.Visible = False
>
>
>
> varCounter = "00:0" & Int(DateDiff("s", dteStartTime2, Now) / 60)
> varCounter = varCounter & ":" _
> & Right("0" & DateDiff("s", dteStartTime2, Now) Mod 60, 2)
> Me.Timer4 = varCounter
>
>
> Else
> varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime2) / 60)
> varCounter = varCounter & ":" _
> & Right("0" & DateDiff("s", Now, dteStartTime2) Mod 60, 2)
> Me.Timer3 = varCounter
>
> End If
>
> End Sub
>
>
> Iv still got a bit of 'tidying' to do on it, but in principle i think its
> working, however i still seem to have a problem with getting 'hours' on the
> timers. ie if i want it to count down from 2hrs i would put in 7200 however
> this comes out as 00:0119:59 and starts counting down. As i said, i have a
> cmd button which when clicked, resets my timer - for info, this is my code in
> that:
>
> Private Sub FPCheck_Click()
> On Error GoTo Err_FPCheck_Click
>
> dteStartTime1 = DateAdd("s", 7200, Now())
> Me.TimerInterval = 1000
> Me.Text4 = ""
> Me.Text4.BackColor = vbWhite
> Me.Overdueby.Visible = False
> Me.LastInspectionOverDueBy.Visible = True
>
> Dim stDocName As String
> Dim stLinkCriteria As String
>
> stDocName = "FPCheckForm"
> DoCmd.OpenForm stDocName, , , stLinkCriteria
>
> Exit_FPCheck_Click:
> Exit Sub
>
> Err_FPCheck_Click:
> MsgBox Err.Description
> Resume Exit_FPCheck_Click
>
> End Sub
>
>
> Hope to hear back from you - your helps been great!
> Thanks
>
>
>
>
>
> "Beetle" wrote:
>
> > That won't work because you are asking the variable varCounter to
> > do two different things at the same time.
> >
> > Under what conditions are Timer3 and Timer4 supposed to start/stop,
> > and are they supposed to count up or down?
> > --
> > _________
> >
> > Sean Bailey
> >
> >
> > "Nick T" wrote:
> >
> > > Hi,
> > > Think i may be biting off more than i can chew here!
> > > Its getting a bit complicated (to me) but ill explain in the hope that you
> > > may be able to help.
> > >
> > > Ok, so i originally started with 2 timers - one timer1 which would count
> > > down - on zero it would change the colour of my text box, and then timer 2
> > > would start counting up. When a user clicks a specific cmd button it resets
> > > timer 1 to start counting down again from a pre programmed amount ie. 2hours,
> > > and resets the backcolour of my text box.
> > > Now, i want to replicate this on the same form, but have 4 timers. Each one
> > > needs to work independantly. The code you gave me worked really well,
> > > however iv been playing to try & modify it to account for another 2 timers,
> > > however not with much success.
> > >
> > > Iv posted the code below which i have been playing with, in the hope that
> > > you may be able to see where i am wanting to go with this.......(hope it
> > > makes sence) but as i said - not having much luck. If you can help great but
> > > let me know if i need to explain my need better:
> > >
> > > Private Sub Form_Timer()
> > >
> > > If DateDiff("s", Now, dteStartTime) < 0 Then
> > > Me.Text4 = "Check Required"
> > > Me.Text4.BackColor = vbRed
> > > Me.Overdueby.Visible = True
> > > Me.LastInspectionOverDueBy.Visible = False
> > > Me.Text5 = "Check Required"
> > > Me.Text5.BackColor = vbRed
> > > Me.OverduebyWt.Visible = True
> > > Me.LastInspectionOverDueByWt.Visible = False
> > >
> > >
> > >
> > > varCounter = "00:0" & Int(DateDiff("s", dteStartTime, Now) / 60)
> > > varCounter = varCounter & ":" _
> > > & Right("0" & DateDiff("s", dteStartTime, Now) Mod 60, 2)
> > > Me.Timer2 = varCounter
> > >
> > > varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime) / 60)
> > > varCounter = varCounter & ":" _
> > > & Right("0" & DateDiff("s", Now, dteStartTime) Mod 60, 2)
> > > Me.Timer4 = varCounter
> > >
> > >
> > > Else
> > > varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime) / 60)
> > > varCounter = varCounter & ":" _
> > > & Right("0" & DateDiff("s", Now, dteStartTime) Mod 60, 2)
> > > Me.Timer1 = varCounter
> > >
> > > varCounter = "00:0" & Int(DateDiff("s", dteStartTime, Now) / 60)
> > > varCounter = varCounter & ":" _
> > > & Right("0" & DateDiff("s", dteStartTime, Now) Mod 60, 2)
> > > Me.Timer3 = varCounter
> > >
> > >
> > >
> > >
> > > End If
> > >
> > >
> > > End Sub
> > >
> > >
> > > "Beetle" wrote:
> > >
> > > > I responded to the previous thread today but I guess you didn't see it.
> > > >
> > > > Here is a simpler, more effective method that should do everything
> > > > you want;
> > > >
> > > > Private Sub Form_Timer()
> > > >
> > > > If DateDiff("s", Now, dteStartTime) < 0 Then
> > > > Me.Text4 = "Check Required"
> > > > Me.Text4.BackColor = vbRed
> > > > Me.Timer2 = Time - TimeValue(dteStartTime)
> > > > Else
> > > > Me.Timer1 = Time - TimeValue(dteStartTime)
> > > > End If
> > > >
> > > > End Sub
> > > >
> > > > --
> > > > _________
> > > >
> > > > Sean Bailey
> > > >
> > > >
> > > > "Nick T" wrote:
> > > >
> > > > > Hi,
> > > > > With help from various.....
> > > > > I have a form with various timers on it which currently only works in
> > > > > minutes & seconds. I have the following code in my on timer event, however i
> > > > > want my timers to be able to run into hours as well as the minutes & seconds
> > > > > - any suggestions what changes i need to make to the following code in order
> > > > > to do this:
> > > > >
> > > > >
> > > > > Private Sub Form_Timer()
> > > > >
> > > > > If DateDiff("s", Now, dteStartTime) < 0 Then
> > > > > Me.Text4 = "Check Required"
> > > > > Me.Text4.BackColor = vbRed
> > > > > varCounter = "00:0" & Int(DateDiff("s", dteStartTime, Now) / 60)
> > > > > varCounter = varCounter & ":" _
> > > > > & Right("0" & DateDiff("s", dteStartTime, Now) Mod 60, 2)
> > > > > Me.Timer2 = varCounter
> > > > > Else
> > > > > varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime) / 60)
> > > > > varCounter = varCounter & ":" _
> > > > > & Right("0" & DateDiff("s", Now, dteStartTime) Mod 60, 2)
> > > > > Me.Timer1 = varCounter
> > > > > End If
> > > > >
> > > > > End Sub
> > > > >
> > > > >
> > > > >
> > > > > Thanks for any help!
> > > > > >> Stay informed about: Timer Code |
|
| Back to top |
|
 |  |
External

Since: May 12, 2008 Posts: 47
|
(Msg. 8) Posted: Mon Nov 24, 2008 3:38 pm
Post subject: RE: Timer Code [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Hi Beetle,
Hope you pick this up.....
Seem to have come across somthing odd with the code you have helped me with:
If i set my timer to say 2 hrs, and there is less that 2hrs remaining of
this day, (eg the time is later than 10:00pm) then the timer reads somthing
along the lines of 23:00:00 and starts counting upwards?
It was odd, cos it worked perfectly earlier, but now it just seemed to stop
working. I turned the system clock on my pc back to allow more than 2 hrs to
be remaining of 'today' (ie before 12midnight) and it worked! Although not
too much of an issue, i thought it was odd - anything i can do to overcome
this??
Thanks
Nick
"Beetle" wrote:
> Try this;
>
> Private Sub Form_Timer()
>
> If DateDiff("s", Now, dteStartTime1) < 0 Then
> Me.Text4 = "Check Required"
> Me.Text4.BackColor = vbRed
> Me.Overdueby.Visible = True
> Me.LastInspectionOverDueBy.Visible = False
>
> Me.Timer2 = Time - TimeValue(dteStartTime1)
> Else
> Me.Timer1 = Time - TimeValue(dteStartTime1)
>
> End If
>
>
> If DateDiff("s", Now, dteStartTime2) < 0 Then
> Me.Text5 = "Check Required"
> Me.Text5.BackColor = vbRed
> Me.OverduebyWt.Visible = True
> Me.LastInspectionOverDueByWt.Visible = False
>
> Me.Timer4 = Time - TimeValue(dteStartTime2)
> Else
> Me.Timer3 = Time - TimeValue(dteStartTime2)
>
> End If
>
> End Sub
>
>
> If the above works for you, then you can remove the varCounter variable
> in the declarations section of your module.
>
> --
> _________
>
> Sean Bailey
>
>
> "Nick T" wrote:
>
> > Hi.... (thanks for reading all that) i know posts are supposed to be kept
> > brief!
> > Anyway, iv solved it - finally got there, however you may be able to tell me
> > if what iv done is against 'access rules' as far as good practice is
> > concerned:
> >
> > So,
> > in my form code i put this in the top part:
> >
> > Option Compare Database
> > Option Explicit
> > Dim dteStartTime1 As Date
> > Dim dteStartTime2 As Date - (this line i added)
> > Dim varCounter As Variant
> >
> > Then in my on timer code i put this:
> >
> > Private Sub Form_Timer()
> >
> > If DateDiff("s", Now, dteStartTime1) < 0 Then
> > Me.Text4 = "Check Required"
> > Me.Text4.BackColor = vbRed
> > Me.Overdueby.Visible = True
> > Me.LastInspectionOverDueBy.Visible = False
> >
> >
> >
> > varCounter = "00:0" & Int(DateDiff("s", dteStartTime1, Now) / 60)
> > varCounter = varCounter & ":" _
> > & Right("0" & DateDiff("s", dteStartTime1, Now) Mod 60, 2)
> > Me.Timer2 = varCounter
> >
> >
> >
> > Else
> > varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime1) / 60)
> > varCounter = varCounter & ":" _
> > & Right("0" & DateDiff("s", Now, dteStartTime1) Mod 60, 2)
> > Me.Timer1 = varCounter
> >
> > End If
> >
> >
> > If DateDiff("s", Now, dteStartTime2) < 0 Then
> > Me.Text5 = "Check Required"
> > Me.Text5.BackColor = vbRed
> > Me.OverduebyWt.Visible = True
> > Me.LastInspectionOverDueByWt.Visible = False
> >
> >
> >
> > varCounter = "00:0" & Int(DateDiff("s", dteStartTime2, Now) / 60)
> > varCounter = varCounter & ":" _
> > & Right("0" & DateDiff("s", dteStartTime2, Now) Mod 60, 2)
> > Me.Timer4 = varCounter
> >
> >
> > Else
> > varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime2) / 60)
> > varCounter = varCounter & ":" _
> > & Right("0" & DateDiff("s", Now, dteStartTime2) Mod 60, 2)
> > Me.Timer3 = varCounter
> >
> > End If
> >
> > End Sub
> >
> >
> > Iv still got a bit of 'tidying' to do on it, but in principle i think its
> > working, however i still seem to have a problem with getting 'hours' on the
> > timers. ie if i want it to count down from 2hrs i would put in 7200 however
> > this comes out as 00:0119:59 and starts counting down. As i said, i have a
> > cmd button which when clicked, resets my timer - for info, this is my code in
> > that:
> >
> > Private Sub FPCheck_Click()
> > On Error GoTo Err_FPCheck_Click
> >
> > dteStartTime1 = DateAdd("s", 7200, Now())
> > Me.TimerInterval = 1000
> > Me.Text4 = ""
> > Me.Text4.BackColor = vbWhite
> > Me.Overdueby.Visible = False
> > Me.LastInspectionOverDueBy.Visible = True
> >
> > Dim stDocName As String
> > Dim stLinkCriteria As String
> >
> > stDocName = "FPCheckForm"
> > DoCmd.OpenForm stDocName, , , stLinkCriteria
> >
> > Exit_FPCheck_Click:
> > Exit Sub
> >
> > Err_FPCheck_Click:
> > MsgBox Err.Description
> > Resume Exit_FPCheck_Click
> >
> > End Sub
> >
> >
> > Hope to hear back from you - your helps been great!
> > Thanks
> >
> >
> >
> >
> >
> > "Beetle" wrote:
> >
> > > That won't work because you are asking the variable varCounter to
> > > do two different things at the same time.
> > >
> > > Under what conditions are Timer3 and Timer4 supposed to start/stop,
> > > and are they supposed to count up or down?
> > > --
> > > _________
> > >
> > > Sean Bailey
> > >
> > >
> > > "Nick T" wrote:
> > >
> > > > Hi,
> > > > Think i may be biting off more than i can chew here!
> > > > Its getting a bit complicated (to me) but ill explain in the hope that you
> > > > may be able to help.
> > > >
> > > > Ok, so i originally started with 2 timers - one timer1 which would count
> > > > down - on zero it would change the colour of my text box, and then timer 2
> > > > would start counting up. When a user clicks a specific cmd button it resets
> > > > timer 1 to start counting down again from a pre programmed amount ie. 2hours,
> > > > and resets the backcolour of my text box.
> > > > Now, i want to replicate this on the same form, but have 4 timers. Each one
> > > > needs to work independantly. The code you gave me worked really well,
> > > > however iv been playing to try & modify it to account for another 2 timers,
> > > > however not with much success.
> > > >
> > > > Iv posted the code below which i have been playing with, in the hope that
> > > > you may be able to see where i am wanting to go with this.......(hope it
> > > > makes sence) but as i said - not having much luck. If you can help great but
> > > > let me know if i need to explain my need better:
> > > >
> > > > Private Sub Form_Timer()
> > > >
> > > > If DateDiff("s", Now, dteStartTime) < 0 Then
> > > > Me.Text4 = "Check Required"
> > > > Me.Text4.BackColor = vbRed
> > > > Me.Overdueby.Visible = True
> > > > Me.LastInspectionOverDueBy.Visible = False
> > > > Me.Text5 = "Check Required"
> > > > Me.Text5.BackColor = vbRed
> > > > Me.OverduebyWt.Visible = True
> > > > Me.LastInspectionOverDueByWt.Visible = False
> > > >
> > > >
> > > >
> > > > varCounter = "00:0" & Int(DateDiff("s", dteStartTime, Now) / 60)
> > > > varCounter = varCounter & ":" _
> > > > & Right("0" & DateDiff("s", dteStartTime, Now) Mod 60, 2)
> > > > Me.Timer2 = varCounter
> > > >
> > > > varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime) / 60)
> > > > varCounter = varCounter & ":" _
> > > > & Right("0" & DateDiff("s", Now, dteStartTime) Mod 60, 2)
> > > > Me.Timer4 = varCounter
> > > >
> > > >
> > > > Else
> > > > varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime) / 60)
> > > > varCounter = varCounter & ":" _
> > > > & Right("0" & DateDiff("s", Now, dteStartTime) Mod 60, 2)
> > > > Me.Timer1 = varCounter
> > > >
> > > > varCounter = "00:0" & Int(DateDiff("s", dteStartTime, Now) / 60)
> > > > varCounter = varCounter & ":" _
> > > > & Right("0" & DateDiff("s", dteStartTime, Now) Mod 60, 2)
> > > > Me.Timer3 = varCounter
> > > >
> > > >
> > > >
> > > >
> > > > End If
> > > >
> > > >
> > > > End Sub
> > > >
> > > >
> > > > "Beetle" wrote:
> > > >
> > > > > I responded to the previous thread today but I guess you didn't see it.
> > > > >
> > > > > Here is a simpler, more effective method that should do everything
> > > > > you want;
> > > > >
> > > > > Private Sub Form_Timer()
> > > > >
> > > > > If DateDiff("s", Now, dteStartTime) < 0 Then
> > > > > Me.Text4 = "Check Required"
> > > > > Me.Text4.BackColor = vbRed
> > > > > Me.Timer2 = Time - TimeValue(dteStartTime)
> > > > > Else
> > > > > Me.Timer1 = Time - TimeValue(dteStartTime)
> > > > > End If
> > > > >
> > > > > End Sub
> > > > >
> > > > > --
> > > > > _________
> > > > >
> > > > > Sean Bailey
> > > > >
> > > > >
> > > > > "Nick T" wrote:
> > > > >
> > > > > > Hi,
> > > > > > With help from various.....
> > > > > > I have a form with various timers on it which currently only works in
> > > > > > minutes & seconds. I have the following code in my on timer event, however i
> > > > > > want my timers to be able to run into hours as well as the minutes & seconds
> > > > > > - any suggestions what changes i need to make to the following code in order
> > > > > > to do this:
> > > > > >
> > > > > >
> > > > > > Private Sub Form_Timer()
> > > > > >
> > > > > > If DateDiff("s", Now, dteStartTime) < 0 Then
> > > > > > Me.Text4 = "Check Required"
> > > > > > Me.Text4.BackColor = vbRed
> > > > > > varCounter = "00:0" & Int(DateDiff("s", dteStartTime, Now) / 60)
> > > > > > varCounter = varCounter & ":" _
> > > > > > & Right("0" & DateDiff("s", dteStartTime, Now) Mod 60, 2)
> > > > > > Me.Timer2 = varCounter
> > > > > > Else
> > > > > > varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime) / 60)
> > > > > > varCounter = varCounter & ":" _
> > > > > > & Right("0" & DateDiff("s", Now, dteStartTime) Mod 60, 2)
> > > > > > Me.Timer1 = varCounter
> > > > > > End If
> > > > > >
> > > > > > End Sub
> > > > > >
> > > > > >
> > > > > >
> > > > > > Thanks for any help!
> > > > > > >> Stay informed about: Timer Code |
|
| Back to top |
|
 |  |
| Related Topics: | Compact DB in Code - Several times over the years I have set up small maintenance programs that compact backend databases at clients. I generally write a small application and log results in a table so the client can check that the compact worked. I then set up a scheduled...
code for mousehook - I'm trying to put the mousehook code in the load event of a switchboard, since this is the first form that is opened when a user logs on. I know zero about code, so what do I need to write in the load/unload event sections of the code for the switchboard...
Delete a constraint from code? - Hi. I've created a relation (referential integrity) between to tables manually in Access. Now I need to delete the relation/constraint (because I need to delete a field), but I don't know the name of the constraint. I need to delete the field..
Phone with/without area code -
Control Source code - How can I join these two codes together .....Thanks for any help ...Bob =IIf([tbGSTOptionsValue]=0,Null,[TaxLabel]) =DLookUp("TaxLabel","tblCompanyInfo") |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|