Scroll Event

Applies To

Frame control, MultiPage control, ScrollBar control, UserForm object.

Description

Occurs when the scroll box is repositioned.

Syntax

For ScrollBar:

Private Sub object_Scroll( )

For MultiPage:

Private Sub object_Scroll( index As Long, ActionX As fmScrollAction, ActionY As
úfmScrollAction, ByVal RequestDx As Single, ByVal RequestDy As Single, ByVal
úActualDx As MSForms.ReturnSingle, ByVal ActualDy As MSForms.ReturnSingle)

For Frame:

Private Sub object_Scroll( ActionX As fmScrollAction, ActionY As fmScrollAction,
úByVal RequestDx As Single, ByVal RequestDy As Single, ByVal ActualDx As
úMSForms.ReturnSingle, ByVal ActualDy As MSForms.ReturnSingle)

The Scroll event syntax has these parts:

Part

Description

object

Required. A valid object name.

index

Required. The index of the page in a MultiPage associated with this event.

ActionX

Required. The action that occurred in the horizontal direction.

ActionY

Required. The action that occurred in the vertical direction.

RequestDx

Required. The distance, in points, you want the scroll bar to move in the horizontal direction.

RequestDy

Required. The distance, in points, you want the scroll bar to move in the vertical direction.

ActualDx

Required. The distance, in points, the scroll bar traveled in the horizontal direction.

ActualDy

Required. The distance, in points, the scroll bar traveled in the vertical direction.


Settings

The settings for ActionX and ActionY are:

Constant

Value

Description

fmScrollActionNoChange

0

No change occurred.

FmScrollActionLineUp

1

A small distance up on a vertical scroll bar; a small distance to the left on a horizontal scroll bar. Movement is equivalent to pressing the up or left arrow keys on the keyboard to move the scroll bar.

fmScrollActionLineDown

2

A small distance down on a vertical scroll bar; a small distance to the right on a horizontal scroll bar. Movement is equivalent to pressing the down or right arrow keys on the keyboard to move the scroll bar.

fmScrollActionPageUp

3

One page up on a vertical scroll bar; one page to the left on a horizontal scroll bar. Movement is equivalent to pressing PAGE UP on the keyboard to move the scroll bar.

fmScrollActionPageDown

4

One page down on a vertical scroll bar; one page to the right on a horizontal scroll bar. Movement is equivalent to pressing PAGE DOWN on the keyboard to move the scroll bar.

fmScrollActionBegin

5

The top of a vertical scroll bar; the left end of a horizontal scroll bar.

fmScrollActionEnd

6

The bottom of a vertical scroll bar; the right end of a horizontal scroll bar.

fmScrollActionPropertyChange

8

The value of either the ScrollTop or the ScrollLeft property changed. The direction and amount of movement depend on which property was changed and on the new property value.

fmScrollActionControlRequest

9

A control asked its container to scroll. The amount of movement depends on the specific control and container involved.

fmScrollActionFocusRequest

10

The user moved to a different control. The amount of movement depends on the placement of the selected control, and generally has the effect of moving the selected control so it is completely visible to the user.


Remarks

The Scroll events associated with a form, Frame, or Page return the following arguments: ActionX, ActionY, ActualX, and ActualY. ActionX and ActionY identify the action that occurred. ActualX and ActualY identify the distance that the scroll box traveled.

The default action is to calculate the new position of the scroll box and then scroll to that position.

You can initiate a Scroll event by issuing a Scroll method for a form, Frame, or Page. Users can generate Scroll events by moving the scroll box.

The Scroll event associated with the stand-alone ScrollBar indicates that the user moved the scroll box in either direction. This event is not initiated when the value of the ScrollBar changes by code or by the user clicking on parts of the ScrollBar other than the scroll box.

See Also

Scroll method.

Example

The following example demonstrates the stand-alone ScrollBar and reports the change in its value as the user moves the scroll box. The user can move the scroll box by clicking on either arrow at the ends of the control, by clicking in the region between scroll box and either arrow, or by dragging the scroll box. When the user drags the scroll box, the Scroll event displays a message indicating that the user scrolled to obtain the new value.

To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains:

  • A ScrollBar named ScrollBar1.
  • Two Label controls named Label1 and Label2. Label1 contains scaling information for the user. Label2 reports the delta value.
    Dim ScrollSaved As Integer        'Previous ScrollBar setting
    
    Private Sub UserForm_Initialize()
        ScrollBar1.Min = -225
        ScrollBar1.Max = 289
        ScrollBar1.Value = 0
    
        Label1.Caption = "-225  -----Widgets-----   289"
        Label1.AutoSize = True
    
        Label2.Caption = ""
    End Sub
    
    Private Sub ScrollBar1_Change()
        Label2.Caption = " Widget Changes " & (ScrollSaved - ScrollBar1.Value)
    End Sub
    
    Private Sub ScrollBar1_Exit(ByVal Cancel as MSForms.ReturnBoolean)
        Label2.Caption = " Widget Changes " & (ScrollSaved - ScrollBar1.Value)
        ScrollSaved = ScrollBar1.Value
    End Sub
    
    Private Sub ScrollBar1_Scroll()
        Label2.Caption = (ScrollSaved - ScrollBar1.Value) & " Widget Changes" _
        & " by Scrolling"
    End Sub