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!

Button repeat function Access 2000 1

Status
Not open for further replies.

vamoose

Programmer
Oct 16, 2005
320
MX
I have a button on a form which exectues a VBA Event Procedure On Click (Mouse). My question is if I continue to hold this button down, is there a way to make this VBA Event Procedure execute again and again until the button is released. Do I need some sort of repeat code or what is this ability called.

Thanks for any suggestions.
 
You could start a function running on Mouse Down, and stop it on Mouse Up, something along the lines of:

Code:
Dim buttonDown

Sub cmdButton_MouseDown()
    buttonDown = True
    myFunction
End Sub
Sub cmdButton_MouseUp()
    buttonDown = False
End Sub

Function myFunction()
    ...
    If buttonDown Then
        myFunction
    End If
End Function



 
I have been researching this MouseDown and MouseUp topic all day now, and I cannot find a solution to my problem. I am using the above code provided by hc98br and I can either make it execute just one time, or the button gets stuck in the down position and runs on.

Here is my application:

Dim ButtonDown
Dim lstitem As ListView

Private Sub MoveUp_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ButtonDown = True
MyFunction
End Sub

Private Sub MoveUp_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
ButtonDown = False
End Sub

Function MyFunction()
Set lstitem = Me.ListView1.Object
DoCmd.SetWarnings False: [List2] = lstitem.SelectedItem: Auto = [List2]: Index = [List2]
If Index = 1 Then MsgBox "Cannot move this line item up any further ", vbOKOnly + vbCritical, "Organize run data": Exit Function
DoCmd.RunSQL "Update tbl_Copy Set Auto = 0 where Auto = " & Auto: AutoNew = Auto - 1
DoCmd.RunSQL "Update tbl_Copy Set Auto =" & Auto & " where Auto = " & AutoNew
DoCmd.RunSQL "Update tbl_Copy Set Auto =" & AutoNew & " where Auto = 0"
DoCmd.SetWarnings True: Call FillWithUnits
ListView1.SetFocus
Set ListView1.SelectedItem = ListView1.ListItems(AutoNew)
If ButtonDown Then MyFunction
End Function

Any ideas please and thank you.
 
Couple of things I can think of....

I am not sure that hc98Br's solution will work exactly as you need...Haven't tested it myself, but it is close. What i think you might try is this:

Put a timer on your form. Have the timer interval short. Borrowing from the previous example:

Code:
Dim ButtonDown

Private Sub MoveUp_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    ButtonDown = True
End Sub

Private Sub MoveUp_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    ButtonDown = False
End Sub

Your timer event should call your Function and your function should look like this:

Code:
Function MyFunction()
    If ButtonDown Then
    Set lstitem = Me.ListView1.Object
    DoCmd.SetWarnings False: [List2] = lstitem.SelectedItem: Auto = [List2]: Index = [List2]
    If Index = 1 Then MsgBox "Cannot move this line item up any further     ", vbOKOnly + vbCritical, "Organize run data": Exit Function
    DoCmd.RunSQL "Update tbl_Copy Set Auto = 0 where Auto = " & Auto: AutoNew = Auto - 1
    DoCmd.RunSQL "Update tbl_Copy Set Auto =" & Auto & " where Auto = " & AutoNew
    DoCmd.RunSQL "Update tbl_Copy Set Auto =" & AutoNew & " where Auto = 0"
    DoCmd.SetWarnings True: Call FillWithUnits
    ListView1.SetFocus
    Set ListView1.SelectedItem = ListView1.ListItems(AutoNew)
    End If
End Function

Of course, I can see a couple problems that might arise from this. If you MouseDown over the button and then move your mouse off the button before releasing it, the code will be "stuck on" until you mouse over, click and then release again....So you may want to add the MouseUp code to the form as well just in case.

You could also keep the Click of the command button to just a one time execution of the code and create a different control that uses a MouseOver event to do the looping....that way, you only have to slide your mouse over this button and the code begins executing until you slide off the button.

Just some thoughts off the top of my head.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
In Design View goto the button's Properties - Other and set the AutoRepeat Property to YES. As long as the button's action don't cause the Current Record to change, the actions will be repeated until the button is released.

For all the poop on this enter AutoRepeat Property in the Access Help box.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
missinglinq . . .

I forgot all about AutoRepeat (never had to use it). Not even in my library. This has now changed!

Way Ta Go! [thumbsup2]

I can't see it used in an application but it would make a great [blue]testing tool! . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Hey, Aceman! The only thing I ever wanted it for was to put behind a home grown navigation button, to move thru records. Of course, moving between records is the one thing you can't use it for!

Linq

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
missinglinq . . .

Althought it can be used for what you've cited, you & I would simply add a combo to go right there! . . .

Anyway you look at it . . . [blue]an excellent post![/blue] [thumbsup2]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Of course, unless your target users are Luddites! Which, sad to say, many of mine are!

Linq ;)>

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top