Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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

Reply With Quote
  #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
Reply With Quote
  #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

Reply With Quote
  #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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:19 AM.


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