Activating Timer after an event

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Stoic
    New Member
    • Jun 2012
    • 68

    Activating Timer after an event

    Hi,
    I have a for in my database with several fields. Now I want for the timer to be activated after entering data into a particular field. I have this but I am not getting the result.

    Code:
    Private Sub Form_Current()
        If Me.Number = "*" Then
            Me.TimerInterval = 500
        Else
            Me.TimerInterval = 0
            Me.lblProcessing.Visible = False
        End If
    End Sub
    Code:
        With Me.lblProcessing
            .Visible = Not Me.lblProcessing.Visible
        End With
    Can anyone help me out on what I am doing wrong here?
    Thanks,
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32633

    #2
    Originally posted by Stoic
    Stoic:
    Now I want for the timer to be activated after entering data into a particular field.
    Your explanation doesn't match the code. The code checks each record it finds.

    For your second code block you give no clues as to where it is found. As such, it is almost no indication of anything at all.

    I suspect if you work a little on your question we will be in a position to be able to help without having to guess too much of what you really want. This should suit everyone.

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      You probably think that Me.Number = "*" will be true if there's anything in the field. That's not correct. An equal operator does not accept wild cards. What you need to do instead is check that the length of the field is larger than 1.

      Comment

      • TheSmileyCoder
        Recognized Expert Moderator Top Contributor
        • Dec 2009
        • 2322

        #4
        Curios why do you need the timer?
        Anyway, as rabbit says there are various ways to check for data.

        One is:
        Code:
        IF len(Me.Number & "")>0 then
        The & "" ensures that should the field be empty (null) then that is handled as well.

        Another approach if you want to be more specific (based on the name of your control might be to use the IsNumeric function.

        Comment

        • Stoic
          New Member
          • Jun 2012
          • 68

          #5
          Thanks guys for the efforts so far. I inadvertently forgot to include where my second code is. Here is my thought.
          I have several fields on my form. Among the fields, I have a field called Number. I also have a label called lblProcessing placed in the form property timer to alternate/flash. Now, I want for the timer to be activated after updating the 'Number' field; when timer is activated, the label 'lblProcessing' will flash, else the timer interval is set at 0 and nothing which means the Number field is empty. My first code:

          Code:
          Private Sub Form_Current()
              If Me.Number = "*" Then
                  Me.TimerInterval = 500
              Else
                  Me.TimerInterval = 0
                  Me.lblProcessing.Visible = False
              End If
          End Sub
          says if the number field is updated then the timer is activated the the 'lblProcessing' label is visible and flashes, else the timer is set at 0 and the 'lblProcessing label stops flashing and not visible.

          My second code
          Code:
          Private Sub Form_Timer()
              With Me.lblProcessing
                  .Visible = Not Me.lblProcessing.Visible
              End With
          End Sub
          runs the timer for the 'lblProcessing' label to flash if the timer is activated.

          I hope I have provided some clarity.
          Thanks

          Comment

          • TheSmileyCoder
            Recognized Expert Moderator Top Contributor
            • Dec 2009
            • 2322

            #6
            The forms current event is fired each time you navigate to a different (or new) record in your form. I think you need to code it differently based on what you have described.

            A single procedure to check:
            Code:
            Private Sub UpdateTimer()
                If IsNumeric(Me.Number) Then
                    Me.TimerInterval = 500
                Else
                    Me.TimerInterval = 0
                    Me.lblProcessing.Visible = False
                End If
            End Sub
            With code in both the FORMS current and the NUMBER CONTROL's afterupdate:
            Code:
            Private Sub Form_Current()
              Call UpdateTimer
            End Sub
            
            Private Sub Number_AfterUpdate()
              Call UpdateTimer
            End Sub
            Hope that Helps.

            Comment

            • Stoic
              New Member
              • Jun 2012
              • 68

              #7
              Thanks TheSmileyCoder, but it didn't work.

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32633

                #8
                Originally posted by Stoic
                Stoic:
                I want for the timer to be activated after updating the 'Number' field; when timer is activated, the label 'lblProcessing' will flash, else the timer interval is set at 0 and nothing which means the Number field is empty.
                As Smiley indicated (and I did earlier also) this is just not logical. The value in your [Number] control can be non-blank without it having been changed in the current sesssion. Your response is very helpful certainly, and leaving bits out of the question is an oversight that many members make. It would probably be helpful if you could resolve for us exactly what you do mean here though. Is it when this value is changed that you want it to flash or is it when the value is other than Null (blank)?
                Originally posted by Stoic
                Stoic:
                Thanks TheSmileyCoder, but it didn't work.
                A perfectly polite and friendly response, but we also need information when something fails. Was there an error message? Were the results other than you expected with no crash? Just saying it doesn't work is generally not very much to work with ;-)

                For the UpdateTimer procedure I'd suggest :
                Code:
                Private Sub UpdateTimer()
                    With Me
                        .TimerInterval = IIf(IsNull(.Number), 0, 500)
                        .lblProcessing.Visible = (.TimerInterval > 0)
                    End With
                End Sub
                For the Timer procedure itself :
                Code:
                Private Sub Form_Timer()
                    With Me.lblProcessing
                        .Visible = Not .Visible
                    End With
                End Sub

                Comment

                • Stoic
                  New Member
                  • Jun 2012
                  • 68

                  #9
                  Thanks for the efforts guys. I just added the code to the afterupdate for the Number field and it worked.
                  Code:
                  Private Sub Number_AfterUpdate()
                  If Me.Number > 0 Then
                          Me.TimerInterval = 500
                      Else
                          Me.TimerInterval = 0
                          Me.lblProcessing.Visible = False
                      End If
                  End Sub
                  Last edited by NeoPa; Feb 19 '13, 04:51 PM. Reason: Fixed misplaced [/Code] tag

                  Comment

                  Working...