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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making your own scroll controls...

Status
Not open for further replies.

BigTeeJay

Technical User
Jun 13, 2001
106
US
I've been searching without much luck on this one. I tried searching all of Tek-tips for the words scroll and vb even (with plenty of results, but none that seemed applicable).

What I am trying to do is, make buttons that act just like
the scroll bars in a form. I dont want to use scrollbars
because I have nested forms, and having the scrollbars at
the edges of a form within another form will look odd, and
not very intuitive.

I thought I could utilize the mousedown event of a button,
but that only performs the action once (only one lines worth). It also doesnt seem to allow the mouse up event to occur (I am sure its because I am not using it correctly yet, but as I said... havent had much luck finding examples). The button goes down, and the code executes, but the button doesnt come back up, and i cant figure out how to essentially loop that code while the mouse is down.

Any one know of the best method for allowing someone to click on a button, and have that button scroll a form as long as they hold the mouse down?

Regards,
Tj
 
Howdy,

If you just need to repeat the code, set the Auto Repeat to 'Yes' this will run the code until you release the button.

So if you had a text box named 'txtTest' and a button named 'cmdTest'. Using the onClick event procedure:

*********************************
Option Explicit

Private Sub cmdTest_Click()
Me.txtTest.Value = Me.txtTest.Value + 1
Me.Repaint
End Sub
*********************************

Let me know if this helps. I would like to see you end result.

flan
 
Make sure it's a command button, not a toggle button.

I have not been able to find any MSDN reference to an AutoRepeat property for command buttons.

Holding the Enter key gives you a repeat, but that's in the keyboard, not the control.

You would need to do something like this:
Form would need a boolean variable for the button, lets call it KeepGoing

The _Click event calls the desired routine, do not put the desired behavior in the _Click event, it needs to be in it's own routine, let's call it TheRoutine.

The _MouseDown event sets KeepGoing to True, and then calls TheRoutine.

The _MouseUp event would set KeepGoing to False.


TheRoutine would have:

Code:
 Do 
'Desired behavior
'some manner of pause
Loop While KeepGoing = True

How you create the pause is up to you.

This is the broad concept, the details could be refined.

Steve
 
flan-
were you refering to using a variable like SteveB was suggesting? (otherwise, I agree I havent ever heard of such a property, and kind find any references to it.. do you have any info on it you could share?)

steveb-
good idea, but maybe too good ;) I tried it, and essentially it loops for quite some time. Its as if even with a quick click, so many _mousedown events are queued up, that it forces it to scroll for far longer time that one would expect. You cant just scroll a few records, it scrolls by a whole bunch very quickly.

I thought I remembered there being something like a pause/sleep routine in VB (that I thought i might be able to use to slow down the scrolling or something). Not sure what to do at this point (still digging around).

Regards (and thank you both),
Tj
 
A little clarification... it doesnt appear to be scrolling for a long time, rather it seems to be an infinite loop... I let it run for awhile, and it scrolled through 6330 records before I killed it with ctrl+brk.

I tried stepping through the code, but it claims that I am not able/allowed to while the form is in design mode (I am thinking of doing either some message boxes, or debug.print 's).

Its as if its not processins the mouse up (I even tried clicking on other controls to force a mouse up event).

Tj
 
howdy,

I use Access 2000. With command buttons, in properties, under the 'Other' tab, there is an 'Auto Repeat' property.
I set this to 'Yes'. Then put the above code in the onClick event procedure. If you click and hold down the button, the code will continually run and update the text box by 1 until released. Let me know if I am still not being clear.

flan
 
flan-
You are absolutely correct, how on earth did I miss that (my apologies). I tried it, and it moves one record, and the button stays pressed in (even after releasing the button).

I checked out the help for this property, and then I found this :(...
"If the code attached to the command button causes the current record to change, the AutoRepeat property has no effect."

Arrrrggg... so close! I am starting to think it may not be possible when using a button to scroll through records on a form (sounds like there is something prohibiting this functionality to work correctly when use for this purpose, such as maybe the moving of a records source causes a repaint, and the the mouse is moved to the down state again, which triggers the mouse down again, which is causing the loop?)

Tj
 
I will look into it some more. I now understand exactly what you want to do, and I think it would be very handy on a few of my forms as well. I will look into it here in a little while, and get back to you. But for the most part I don't think the auto repeat property will be of value, as you already pointed out. Sorry for not understanding the original problem on the first go round.

flan
 
Its really odd, if I click quickly (click once, button goes down, click again, button goes up) the button is acting like a toggle button.

If I wait for sec or more between clicks, it doesnt come back up (or if I just click once). I tried inserting a doevents method, hoping maybe it would allow the app/os to handle the mouseup event, but to no avail.

I think the key is figuring out what is breaking the normal event handeling.
 
I think I figured out why steveb's method isnt working (correct me if I am wrong...)

Here is the code i have first off (I noticed I didnt originally have it exactly how you had written, but after correctly it, it still has the same problem...)

Private Sub cmdNextRec_Click()
mvRs acNext
End Sub

Private Sub cmdNextRec_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
bKeepScrolling = True
mvRs acNext
End Sub

Private Sub cmdNextRec_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
bKeepScrolling = False
End Sub

Private Sub mvRs(lDirection As Long)
Do
DoCmd.GoToRecord , , lDirection
Loop While (bKeepScrolling = True)
End Sub

...what I think is happening is, when the mousedown even fires, it calls the mvRs routine. And since the value of our bool flag is true, it loops, and loops, and loops... it gets stuck in the loop and execution continues there never to come back out to handle the mouse up.

Isnt there a way to tell VB that a routine should respond to events? (I am looking into it now, but thought I would post that in case anyone had any ideas, or could remember off the top of their head).

Also, I tried inserting a msgbox as well as using SENDKEYS {PGDN} rather than movenext (so I could debug) and the outcome is the same.

Tj
 
I think the issue is the onMouseUp event is called only after the onMouseDown event has completed running. The onMouseUp is getting called, but not until I have run through all my records. So really, once you intialize 'bKeelScrolling' through the onMouseDown event, that is keep constant until all records are cycled through. I can't think of a way to interupt this procedure to allow the other one to kick off. So, the best I can offer is to continue with the 'AutoRepeat' = True method. It won't have the 'echo' effect of the scrolling down records, but it will move record to record. Also, for some reason the command button wants to stay in focus, not sure why but that is why I used the .SetFocus action.

******************************
Option Compare Database
Option Explicit
'
Private Sub cmdTest_Click()
'
Me.txtTest.Value = Me.txtTest.Value + 1
Me.Repaint
End Sub
'
Private Sub cmdTest_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
'
On Error Resume Next
DoCmd.GoToRecord , Me.Name, acGoTo, Me.txtTest.Value
Me.Repaint
Me.txtTest.SetFocus
End Sub

**************************

I will continue to think about it and I will keep this thread marked. Let me know if you come up with anything, because the idea could be very useful.

flan
 
Howdy,

I think I got it figured out. Create a sub form that is not linked, say "Form2". Move the command buttons to that form. Using the AutoRepeat the following code should work:

****************************************
'
Option Compare Database
Option Explicit
'
Private Sub cmdTest_Click()
On Error Resume Next
'
Me.txtTest.Value = Me.txtTest.Value + 1
DoEvents
DoCmd.GoToRecord , "Form1", acGoTo, Me.txtTest.Value
End Sub

Private Sub cmdTest2_Click()
On Error Resume Next
'
Me.txtTest.Value = Me.txtTest.Value - 1
DoEvents
DoCmd.GoToRecord , "Form1", acGoTo, Me.txtTest.Value
End Sub

****************************************

You have an extra form, but at least it scrolls properly. Let me know if that helps.

flan
 
That is a good idea/interesting. It would probably work for what I am trying to do (in essence at least).

The whole reason I wanted to do this was because I had a main form, and two subforms, and I didnt want it to look odd with the scroll bars in the sub forms (rather than the main form). So I could put these buttons on the main form instead, resize my subforms and keep the same look. And since the main form isnt attached to the record source, it should work great.

I would still like to find a more elegant way (using the mousedown/mouseup, etc events) but this certainly looks like it would do the job!

I am trying to get this app out the door, so I dont have time now to do the changes, but I will try to in the next few days and see how it works.

Tj
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top