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