Solved

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

Posted on 2011-09-29
2
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 34

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
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 …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

751 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