Solved

I need to parse list box rows. VBA

Posted on 2008-06-11
6
1,381 Views
Last Modified: 2013-11-28
I have a multiple column list box. I need to iterate through each row and read the column values
What is the syntax?

For example:

Dim intCtr as integer
Dim strCol0Value as string
Dim strCol1Value as string

For intCtr=0 To listbox.Listcount -1
  strCol0Value =  MyValuelistbox (??)
  strCol1Value  MyValuelistbox (??)

Next intCtr

Or can I declare listbox items ?

For each item in listbox
   strCol0Value=??
   strCol0Value=??
Next item

thanks
0
Comment
Question by:Dovberman
[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
  • 3
  • 3
6 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 21764588
Dovberman,

Why not just iterate through the Listbox's source Table (or Query)?

What exactly are you trying to accomplish here?

JeffCoachman
0
 

Author Comment

by:Dovberman
ID: 21767453
The source is a value list. There are 2 list boxes. One contains all available choices. The other contains the choices that were selected from list 1.

I need to update a table based on the items in list 2.
0
 

Author Comment

by:Dovberman
ID: 21767477
I found code for parsing and finding selected rows. Since all rows need to be read, I can remove the selected criteria.

  For intCtr = 0 To lstApplicants.ListCount - 1
        'isSelected = lstApplicants.Selected(intCtr)
        'If isSelected Then
             lstApplicants.ItemData (intCtr) ' returns the data from column 0
            'Do Stuff
        End If
     Next
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 250 total points
ID: 21770047
Dovberman,

If this is a multi-select listbox, you can use code like this to "de-select all the selected rows:

Dim varItem As Variant
Dim ctl As Control

Set ctl = Me.lstCustomers

    'Loops through all the Items and turns them off
    For Each varItem In ctl.ItemsSelected
        ctl.Selected(varItem) = False
    Next varItem

You will have to modify the object names to match yours.

JeffCoachman
0
 

Author Closing Comment

by:Dovberman
ID: 31466320
Thanks for the extra information
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 21774678
;-)
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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…

718 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