Solved

Find if itemdata value in listbox matches current variable

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

776 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