Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Click and Hold: MouseDown and Timer 1

Status
Not open for further replies.

sgidley

Programmer
Nov 19, 2008
20
US
Access 2003:

I have a situation where the user clicks an "up arrow" Command Button in order to re-order records. I want to allow the user to "click and hold" this button to prevent sometimes having to click many times. The software should halt for a second and then simulate rapid fire clicking. The natural choice seems to me to be the Timer function built into the Form.

So I have:
Code:
Private Sub Promote_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Me.TimerInterval = 1000
End Sub

Private Sub Promote_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Me.TimerInterval = 0
End Sub

Private Sub Form_Timer()
    Me.TimerInterval = 200
    Call Promote_Click
End Sub
I can not get the Timer Event to start firing until after I release the mouse button (If I comment out the Me.TimerInterval = 0 in the MouseUp event). I can put a few "Promote_Click" calls directly in the MouseDown event and it works fine while still holding the mouse button.

Does anyone know why I can't get the Timer Event to fire while holding the mouse button down?

This may or may not be part of the same problem but...
Say I get the timer firing by leaving the code the same as above but removing the MouseUp event. Now, if I click and hold the mouse anywhere on the form, the timer event ceases to fire.

Any Ideas how to get around this or what causes it?

Thanks!

 
Why not using Click & Double Click events?
Or am I missing something?

You can disable the command button soon after the single click the run your code enable it

Code:
Private Sub Promote_Click()
    Me.Text1.SetFocus
    Me.Promote.Enabled = False
    'Do stuff here
    Me.Promote.Enabled = True
End Sub

Zameer Abdulla
 
Yes, I think you may be missing what my goal is.

As an example, say you are using an alarm clock or a car stereo and you are setting the time. Now say there is only a "Time up" and a "Time Down" button. Each time you press the button, the time changes by one minute. To change the time by 4 hours, it would take 4 * 60 button-pushes... 240 clicks. So what is your natural action to take? Hold down the button. Watch the numbers start rolling through and then release the button when you are close to where you want to be and start clicking again.

This is what I am trying to achieve. I have a listbox with a value selected. Pressing the "Promote" button moves the selected value up one place in the list, or promotes it. I have written the code to do this and it works fine. If the user wants to promote this value by 25 items, I want them to be able to click and hold the promote button and watch it ascend, instead of having to click 25 times.

I have already described the problems I run in to when I try this with Access Forms. Any help would be greatly appreciated!
 
Try using a slider control inserted on the form from the INSERT > ACTIVEX CONTROLS menu. Se the maximum value of the slider to the listbox items count.
you may then use something like this
Code:
Private Sub Slider6_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Long, ByVal y As Long)
    Me.Label4.Caption = Me.Slider6.Value
End Sub


Private Sub Slider6_Updated(Code As Integer)
    Me.Label4.Caption = Me.Slider6.Value
End Sub

Zameer Abdulla
 
That sounds like a very reasonable alternative, and I did not know how to get to the slider control so thanks for letting me know! I may give it a try later.
 
Another alternative is "Microsoft Forms SpinButton" that is more easy to use, inserted from the same location. That supports Click & Hold to increase/decrease value.

Code:
Private Sub SpinButton2_Updated(Code As Integer)
    Me.Text10 = Me.SpinButton2.Value
End Sub


Zameer Abdulla
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top