Solved

Find if itemdata value in listbox matches current variable

Posted on 2010-08-12
3
240 Views
Last Modified: 2012-05-10
I have a piece of code which is pulling a value from an SQL table and assigning it to a variable called MVID.  I also have a listbox called lstAxis which has multiple select set on.  The 1st item in the listbox is "ALL" and after that it is populated with data which has a numeric value for each item's .itemdata.

What I need to do is run some code if the MVID variable matches EXACTLY a seleted item's .itemdata value or the ALL item.

I have looked at instr but that seems to throw up false negatives for instance if MVID = 2 then the code runs if the item's .itemdata is 2 or 222 or 123 etc.

Thanks in advance for your help  
0
Comment
Question by:simonwait
  • 2
3 Comments
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33422984
Try this:
 
 If MVID = your item's .ItemData Then
 
0
 
LVL 1

Author Comment

by:simonwait
ID: 33423030
But I need to check multiple items in the list as there could be several selected.  Is there a way of looping?
0
 
LVL 17

Accepted Solution

by:
Zhaolai earned 500 total points
ID: 33423378
Try this:

    Dim i As Integer

    For i = 0 To List1.ListCount - 1

        If List1.Selected(i) Then

            If List1.ItemData(i) = MVID Then

                'match found

            End If

        End If

    Next

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

758 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

21 Experts available now in Live!

Get 1:1 Help Now