Solved

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

Posted on 2011-09-29
2
155 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
Comment Utility
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
Comment Utility
ThANKS
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

763 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now