?
Solved

Find if itemdata value in listbox matches current variable

Posted on 2010-08-12
3
Medium Priority
?
255 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
[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
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 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

801 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