PDA

View Full Version : Scrolling to a specific row in a list box



Mavver
08-15-2008, 03:22 AM
Is it possible via a button on a form to press it, and for a list box on the same form to scroll down to a specific row?

I have a list box with 160 rows in it, and rather than have the user scroll down constantly to find a record, I would like to give them a little help by the list box automatically scrollin down to a specific point.

any help with the code would be much appreicated.

thanks in advance

Mav

OBP
08-15-2008, 03:54 AM
Mav, why bother when a Combo box allows the user to just type the letters in and it jumps to the row with those letters?

Mavver
08-15-2008, 04:06 AM
The database is being used to allow the user to enter specific data about specific areas in the UK, so they may want to enter data on Bolton for instance....however they may want to enter data on Bolton, Manchester and Liverpool all at the same time.

The database is done and dusted and everything is working perfectly however this is a nice little touch to help them out so that they dont have to scroll through 160odd entries to find specific entries

I figured have a button which took them direct to the "F"s etc

I found this code


Private Sub cmdListIndex_Click()
On Error GoTo Err_cmdListIndex_Click

' Always make NumRows an odd number
' if you want selected Row to be in the
' middle of the ListBox.

' NumRows is the number of completely visible rows in the ListBox
Const NumRows = 7
' Row we want displayed in middle of ListBox.
Dim intDesiredRow As Integer

' Arbitrarily select the 24th row.
intDesiredRow = 24
' ListBox must have the Focus
Me.List2.SetFocus
' Force ListBox to start from the top
Me.List2.ListIndex = 1

' Force the Scroll offset we desire
Me.List2.ListIndex = intDesiredRow + (NumRows / 2)
' Now select the row without further scrolling
Me.List2.ListIndex = intDesiredRow

Exit_cmdListIndex_Click:
Exit Sub

Err_cmdListIndex_Click:
MsgBox Err.Description
Resume Exit_cmdListIndex_Click

End Sub


but it just falls over saying I am not using the listindex property correctly.