Solved

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

Posted on 2011-09-29
2
186 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying 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

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

680 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