Using timer for a text box

  • Does anyone no a better way

     

    If Now > ([1st Treatment Date] + 105) Then

    Start = Timer

    Do While Timer < Start + 15

    RedFlag1.Visible = True

    DoEvents

    Loop

    RedFlag1.Visible = False

    Else

    RedFlag1.Visible = False

    End If

  • In a standard (non-form) module, paste the following:

    Option Compare Database

    Option Explicit

    Global myStart As Double

    In your form, set the timer interval = 0.  In the afterupdate of your control, or form_current if the data is from an existing record, set the timer interval to something like 100 milliseconds and set the value of the myStart variable.  Like so:

    Private Sub Ctl1st_Treatment_Date_AfterUpdate()

         Me.TimerInterval = 100

         myStart = CDbl(Now())

    End Sub

    Then, in the timer event, check for data validity and turn on or off the flag as needed.  You don't need the loop or the doevents as the timerinterval will handle it.

    Private Sub Form_Timer()

    'check for data validity before continuing

        If IsNull(Me.Ctl1st_Treatment_Date) Or Me.Ctl1st_Treatment_Date = "" Then Exit Sub

        If IsDate(Me.Ctl1st_Treatment_Date) = False Then Exit Sub

    'check time constraint from populating myStart (24/60/60/60 = about 10 seconds' worth of 1 day)

        If CDbl(myStart) + (24 / 60 / 60 / 60) > CDbl(Now()) Then 'show only for 10 seconds

    'check for need to show flag

            If CDate(myStart) <= (CDate(Me.Ctl1st_Treatment_Date) + 105) Then

                Me.Label0.Visible = False

                'turn off timer if not needed

                Me.TimerInterval = 0

            Else

                Me.Label0.Visible = True

            End If

        Else

            Me.Label0.Visible = False

            'turn off timer if not needed

            Me.TimerInterval = 0

        End If

    End Sub

    Metra

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply