Resetting the form timer (1 Viewer)

John Sh

Member
Local time
Today, 23:27
Joined
Feb 8, 2021
Messages
410
I have a textbox that should display for 6 seconds then disappear.
I am using the form timer to control this but the time the textbox stays visible is random, from virtually nothing up to the desired 6 seconds.
See the code below.
All my reading indicates setting the timer interval to 0 should restart the timer but this seems not to be the case.
If I set the interval to 0 in the form properties the timer does not start even after me.TI = 6000
Is there a way, other than close and open the form, to consistently reset the timer to 0?
All the code below the timer interval works fine, it's just the timer that's a problem

Code:
Private Sub Form_Timer()
    Me.TimerInterval = 0
    Me.TimerInterval = 6000
    If Me.txtMessage.Visible = True Then
        Me.txtMessage.Visible = False
    End If
    If Me.txtAllGood.Visible = True Then
        Me.txtAllGood.Visible = False
    End If
    If Me.txtExpanded.Visible = True Then
        Me.txtExpanded.Visible = False
    End If
    If strBC > "" Then
        Me.BtnBCPhoto.Visible = True
    End If
    If strHerb > "" Then
        Me.btnJPG.Visible = True
    End If
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:27
Joined
Oct 29, 2018
Messages
21,473
Hi. What do you mean by "resetting" the timer? If you want the textbox to show or hide every 6 seconds, then you don't set the Timer Interval to 0 - you leave it at 6000.
 

John Sh

Member
Local time
Today, 23:27
Joined
Feb 8, 2021
Messages
410
Sorry. My explanations always make sense to me but not always to others.
The textbox is turned on by the gotfocus event of some controls. It is then displayed above the relevant control, as an instruction, for the 6 seconds then turns off. It is not a cyclic on / off situation.
If the textbox triggers on partway through a timer cycle it only stays on for the remainder of that cycle.
So, if the timer interval is set to 6000 and the timer count is at 5000 when textbox.visible = true, textbox.visible = false happens after 1 second.
What I need to do is have the textbox on for the full 6 seconds. I could use a loop but that means no other activity can take place until the loop exits. The form timer, on the other hand, allows activity while it is running, so one can be inputting data while the textbox is still visible.
Hope that makes sense.
John
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:27
Joined
Oct 29, 2018
Messages
21,473
Sorry. My explanations always make sense to me but not always to others.
The textbox is turned on by the gotfocus event of some controls. It is then displayed above the relevant control, as an instruction, for the 6 seconds then turns off. It is not a cyclic on / off situation.
If the textbox triggers on partway through a timer cycle it only stays on for the remainder of that cycle.
So, if the timer interval is set to 6000 and the timer count is at 5000 when textbox.visible = true, textbox.visible = false happens after 1 second.
What I need to do is have the textbox on for the full 6 seconds. I could use a loop but that means no other activity can take place until the loop exits. The form timer, on the other hand, allows activity while it is running, so one can be inputting data while the textbox is still visible.
Hope that makes sense.
John
Are you talking about Hints or Tips for each Textbox? Are you able to post a sample copy of your db to show what you're trying to do?

To prevent triggering a textbox halfway into a timer, you should only set the timer when the textbox is activated. But, if you're trying to trigger multiple textboxes, then you'll need to add a facility to track when each textbox started, so you can make sure they stay on for the full time. To do this, you will need to set your Timer Interval to 1000 and perform the necessary checks to turn off the appropriate textbox.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:27
Joined
May 7, 2009
Messages
19,245
here is a sample Tooltip.
 

Attachments

  • 6sec_tooltip.accdb
    392 KB · Views: 379

John Sh

Member
Local time
Today, 23:27
Joined
Feb 8, 2021
Messages
410
1. The gotfocus event of a control triggers the textbox.
Code:
Private Sub cboCollector_gotfocus()
    Call newPosition("N")
    Call show(" Records the name of the primary collector of this specimen.", "E", "P", [Forms]![main collection])
    Me.cboCollector.BackColor = RGB(218, 255, 94)
End Sub

2. sub Newposition() repositions the textbox above and to the left of cboCollector with a message indicating how names are entered.
Code:
Private Function newPosition(str As String)
    Dim ctop As Integer
    Dim cLeft As Integer
    Dim currentctrl As Control
    If intLevel < 3 Then
        Set currentctrl = Me.ActiveControl
        ctop = [currentctrl].Top - [currentctrl].Height - 250
        cLeft = [currentctrl].Left - 2600
        Me.txtMessage.Top = ctop
        Me.txtMessage.Left = cLeft
        Call showInstruct(str, [Forms]![main collection])
    End If
End Function

3. Newposition then calls showinstruct which displays the textbox with the relevant message at the desired position.
Code:
Public Sub showInstruct(strIn As String, ByVal frm As Form)
    Dim dt As Date: dt = Now
    frm.[txtAllGood].Visible = False
    If strIn = "N" Then
        strIn = "Please enter names as  ""Smith. J.""   Titles should not be included"
    ElseIf strIn = "D" Then
        strIn = "Dates can be entered in any format. They will display as " & Date
    End If
    frm.txtMessage.Width = Len(strIn) * 120
    frm.txtMessage = strIn
    frm.txtMessage.Visible = True
End Sub

4. The form timer event then controls the length of time for which the textbox is visible, in theory.
Note that I have removed the if statements in this code, they served no purpose.
Code:
Private Sub Form_Timer()
    Me.TimerInterval = 0
    Me.TimerInterval = 6000
    Me.txtMessage.Visible = False
    Me.txtAllGood.Visible = False
    Me.txtExpanded.Visible = False
    If strBC > "" Then
        Me.BtnBCPhoto.Visible = True
    End If
    If strHerb > "" Then
        Me.btnJPG.Visible = True
    End If
End Sub

What I need from all of this is a way to reset the form timer count to 0 so thet my textbox is visible for the full 6 seconds.
I really don't know how to better explain or describe this problem.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:27
Joined
Oct 29, 2018
Messages
21,473
What I need from all of this is a way to reset the form timer count to 0 so thet my textbox is visible for the full 6 seconds.
If what I said is what you're trying to do (aka tooltip), then you don't reset the timer to 0 or even use 6000. You would just keep it at 1000 and do the turning on and off in your code. Check out @arnelgp's posted demo to see if it does what you want.
 

John Sh

Member
Local time
Today, 23:27
Joined
Feb 8, 2021
Messages
410
here is a sample Tooltip.
Thanks for that. Putting the timerinteval statement in the timer event was the problem.
I've put in into the showInstruct sub and it works fine.
How simple when you know.
Thanks again. much appreciated.
John
 

John Sh

Member
Local time
Today, 23:27
Joined
Feb 8, 2021
Messages
410
If what I said is what you're trying to do (aka tooltip), then you don't reset the timer to 0 or even use 6000. You would just keep it at 1000 and do the turning on and off in your code. Check out @arnelgp's posted demo to see if it does what you want.
If I don't set the timer in the showinstruct sub then the visible time is random. Setting it in the showinstruct sub ensures correct timing each time it is called. If a subsequent call is within the 6 seconds of a previous call the second call will still run for the correct time.

Thank you all for your time and knowledge.
John
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:27
Joined
Oct 29, 2018
Messages
21,473
If I don't set the timer in the showinstruct sub then the visible time is random. Setting it in the showinstruct sub ensures correct timing each time it is called. If a subsequent call is within the 6 seconds of a previous call the second call will still run for the correct time.

Thank you all for your time and knowledge.
John
Hi. Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Top Bottom