Solved

code for determining which record not working after changing to optionstyle listbox

Posted on 2011-09-29
2
179 Views
Last Modified: 2012-05-12
vba 2003
excel
userform

I'm using a label on a form to show which record I'm on in a listbox.

The code will not work now since I switched to a :
fmListStyleOption
and
MultiselectExt

???

Thanks
fordraiders
Private Sub ListBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Dim str As String
Dim strGparts As String
Dim j As Integer
Dim i As Integer

str = "Items Returned"
strGparts = "Items Returned"

'note ListBox indexes from zero and the array 'arr' is base 1
    j = Me.ListBox1.ListIndex
    j = j + 1

i = Me.ListBox5.ListIndex
i = i + 1


Me.Label11.Caption = j & " " & "Of" & " " & Me.ListBox1.ListCount & " " & str
Me.Label17.Caption = i & " " & "Of" & " " & Me.ListBox5.ListCount & " " & strGparts
End Sub

Open in new window

0
Comment
Question by:fordraiders
2 Comments
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 36817989
ListIndex doesn't work in the same way with a multiselect listbox.

If you want to find the selected record you can try this:
For idx = 0 To Listbox1.ListCount-1

           If Listbox1.Selected(idx) = True Then
                j=idx+1
                Exit For
           End If
Next idx

For idx = 0 To Listbox5.ListCount-1

           If Listbox5.Selected(idx) = True Then
                i=idx+1
                Exit For
           End If
Next idx

Open in new window

0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 36907712
ThANKS
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question