Solved

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

Posted on 2011-09-29
2
174 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

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 …
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

770 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