Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
| Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 5th, 2007, 09:50 AM
Authorized User
Points: 82, Level: 1
Points: 82, Level: 1 Points: 82, Level: 1 Points: 82, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , USA.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

  #2 (permalink)  
Old June 5th, 2007, 10:14 AM
Friend of Wrox
 
Join Date: Jan 2005
Location: Kansas City, Missouri, USA.
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
  #3 (permalink)  
Old June 5th, 2007, 11:01 AM
Authorized User
Points: 82, Level: 1
Points: 82, Level: 1 Points: 82, Level: 1 Points: 82, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , USA.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

  #4 (permalink)  
Old June 5th, 2007, 11:06 AM
Friend of Wrox
 
Join Date: Jan 2005
Location: Kansas City, Missouri, USA.
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple Listbox values in another listbox terryv Excel VBA 0 June 27th, 2007 07:01 AM
How can I Reference Value in Listbox dlandolin Access VBA 3 June 6th, 2007 10:12 AM
get reference name demac43 Excel VBA 2 November 20th, 2006 02:35 PM
in need of reference! alialibidad ASP.NET 2.0 Professional 0 June 3rd, 2006 04:11 PM
I'm back :) Listbox var from listbox MichaelTJ .NET Web Services 2 October 21st, 2003 07:06 PM





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