Solved

Find if itemdata value in listbox matches current variable

Posted on 2010-08-12
3
251 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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

695 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