View Full Version : [SOLVED] Listbox navigation
gibbo1715
01-22-2005, 05:59 AM
I have a listbox open a userform and there are two things i would like to be able to do
the first I am sure is quite easy (When you know how) and thats to add a previous and next button to my user form to select the item in the list box
the second is to be able to type into a text box that will search the list box for a match.
Thanks in advance
Gibbo
Jacob Hilderbrand
01-22-2005, 06:50 AM
Try this code.
Option Explicit
Private Sub CommandButton1_Click() 'Previous
Dim n As Long
n = Me.ListBox1.ListCount - 1
Select Case Me.ListBox1.ListIndex
Case Is < 1
Me.ListBox1.ListIndex = n
Case Else
Me.ListBox1.ListIndex = Me.ListBox1.ListIndex - 1
End Select
End Sub
Private Sub CommandButton2_Click() 'Next
Dim n As Long
n = Me.ListBox1.ListCount - 1
Select Case Me.ListBox1.ListIndex
Case Is < n
Me.ListBox1.ListIndex = Me.ListBox1.ListIndex + 1
Case Else
Me.ListBox1.ListIndex = 0
End Select
End Sub
Private Sub CommandButton3_Click() 'Search
Dim Search As String
Dim n As Long
Dim i As Long
Dim j As Long
Search = Me.TextBox1.Text
n = Len(Me.TextBox1)
j = Me.ListBox1.ListCount - 1
For i = 0 To j
If Left(Me.ListBox1.List(i), n) = Search Then
Me.ListBox1.Selected(i) = True
Exit For
End If
Next
End Sub
gibbo1715
01-22-2005, 06:59 AM
Jake i cant thank you enough,
this works great
Gibbo
Jacob Hilderbrand
01-22-2005, 07:02 AM
Glad to help :beerchug:
Take Care
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.