p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Access (http://p2p.wrox.com/forumdisplay.php?f=18)
-   -   How can I Reference Value in Listbox (http://p2p.wrox.com/showthread.php?t=58732)

dlandolin June 5th, 2007 09:50 AM

How can I Reference Value in Listbox
 
Hi,
I've been struggling with this seemingly simple problem for two days now!! How can I reference a value in a listbox? Nothing I try seems to work!! This is my current code:
 Me!lstCheckOut.SetFocus
 Me!lstCheckOut.Selected(0) = True
 data = lstCheckOut.ItemData(0)
 MsgBox data

Please help if you can.
Thanks,
Dave


dartcoach June 5th, 2007 10:14 AM

Dave,
Your listbox values are indexed from 0. you have to loop thru them until you find the one that has been selected. This example shows with an index on the listbox.

   For I = 0 To Me.lstCheckOut.ListCount - 1
      If Me.LstCheckOut.Selected(I) = True Then
         MsgBox Me.LstCheckOut.Column(1, I)
      End If
   Next I

Hope this helps.

Kevin

dartcoach

dlandolin June 5th, 2007 11:01 AM

Kevin,

Thanks for responding. I wanted to loop through them whether they were selected or not. This is how I got it to work:
For i = 0 To lstCheckOut.ListCount - 1
    Me!lstCheckOut.SetFocus
    data = lstCheckOut.Column(0, i)
    MsgBox data
Next i

Thanks Again,
Dave


dartcoach June 5th, 2007 11:06 AM

Glad to help. Didn't realize you wanted to loop through them. You could shorten that code:
For I = 0 to lstCheckout.listcount - 1
  msgbox lstCheckout.column(0,I)
next I

You don't have to set the focus, or move the data to a variable, unless you need to for another reason.

Kevin

dartcoach


All times are GMT -4. The time now is 08:53 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.