Scrolling in a form's listbox

C

cht13er

Hey guys, I'd really appreciate your help!

I have a listbox on a userform that gets populated with a number of
"rows" based on the user's selections in a previous form. Because the
listbox has ten columns and the scrollbar is waaay off to the right, I
wanted to add a second scroll bar on the form, just to the left of the
listbox. When the scroll bar is used, the listbox will scroll up and
down.

I think I've figured out how to get from the scrollbar how many rows
the user wants to move up or down ... but I have no idea how to
"scroll" the listbox! I've attached the code I'm using below:

Private Sub ScrollBar1_Change()
'Declarations
Dim iCounter As Integer
'Scroll only if listbox is not empty
If frmRecordsResult.ListBox1.ListCount > 0 Then
'unselect all, select chosen.
For iCounter = 0 To frmRecordsResult.ListBox1.ListCount - 1
If iCounter = ScrollBar1.Value Then
frmRecordsResult.ListBox1.Selected(iCounter) = True
Else
frmRecordsResult.ListBox1.Selected(iCounter) = False
End If
Next iCounter
'scroll in listbox
frmRecordsResult.ListBox1.TabIndex =
Application.WorksheetFunction.Max(ScrollBar1.Value, 1) - 1

frmRecordsResult.ListBox1.Selected(Application.WorksheetFunction.Max(ScrollBar1.Value,
1) - 1) = True
'ADD A LINE TELLING THE LISTBOX TO "SCROLL" HERE
End If
End Sub

Thanks for any help!

Chris
 
C

cht13er

Hey guys, I'd really appreciate your help!

I have a listbox on a userform that gets populated with a number of
"rows" based on the user's selections in a previous form. Because the
listbox has ten columns and the scrollbar is waaay off to the right, I
wanted to add a second scroll bar on the form, just to the left of the
listbox. When the scroll bar is used, the listbox will scroll up and
down.

I think I've figured out how to get from the scrollbar how many rows
the user wants to move up or down ... but I have no idea how to
"scroll" the listbox! I've attached the code I'm using below:

Private Sub ScrollBar1_Change()
'Declarations
Dim iCounter As Integer
'Scroll only if listbox is not empty
If frmRecordsResult.ListBox1.ListCount > 0 Then
'unselect all, select chosen.
For iCounter = 0 To frmRecordsResult.ListBox1.ListCount - 1
If iCounter = ScrollBar1.Value Then
frmRecordsResult.ListBox1.Selected(iCounter) = True
Else
frmRecordsResult.ListBox1.Selected(iCounter) = False
End If
Next iCounter
'scroll in listbox
frmRecordsResult.ListBox1.TabIndex =
Application.WorksheetFunction.Max(ScrollBar1.Value, 1) - 1

frmRecordsResult.ListBox1.Selected(Application.WorksheetFunction.Max(ScrollBar1.Value,
1) - 1) = True
'ADD A LINE TELLING THE LISTBOX TO "SCROLL" HERE
End If
End Sub

Thanks for any help!

Chris

Anyone?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top