Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

listbox always returns null though item is programmatically selected

Posted on 2013-12-08
4
Medium Priority
?
1,468 Views
Last Modified: 2013-12-08
hi guys,

this question has been asked quite a few times before and i've been doing some searching but i can't really pinpoint it.

i have a listbox - value list and non-multiselect. is use the

me.listbox.selected(0) = true

line of code to select the 1st row and then i try and retrieve the value using

msgbox listbox

it always comes up as a null value.

according to this thread DoDahD says we've got to use the default value of the listbox to set the value, not just aesthetically highlight the first row

http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_27245421.html

however reading other threads it seems that there could be other ways. i'm not sure and here's a quick sample database attached to demonstrate / test this

Question --> how can i select a row from the listbox aesthetically and in the value at the same time?
Listbox-Problem.mdb
0
Comment
Question by:developingprogrammer
[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
  • 2
4 Comments
 
LVL 24

Assisted Solution

by:Bitsqueezer
Bitsqueezer earned 1000 total points
ID: 39704040
Hi,

it's really simple: Set the value of the listbox to the wanted one, not the selection.

Me.lstTesting = 1

In this case it is selected and the value is set. You only need to use the value of the bound column. That of course only works if you do not have multi-select on as there is no single value in this case. Here you need to use the selection and then go through the selection collection to find out which one is selected.

Cheers,

Christian
0
 

Author Comment

by:developingprogrammer
ID: 39704129
thanks Christian!! = ))

the above attached database is just a proof of concept but in my real database i'm dynamically filling in all the worksheets of an excel workbook. so i don't know the value before hand.

i could of course use the column property and get the value of the first row first column, but i was wonder - is there a "lazier" way to do it? = P  = ))
0
 
LVL 48

Accepted Solution

by:
Dale Fye earned 1000 total points
ID: 39704194
Use the itemdata property of the list:

me.lstTesting = me.lstTesting.itemdata(0)

or, if you have the Column headers turned on:

me.lstTesting = me.lstTesting.itemdata(1)
0
 

Author Comment

by:developingprogrammer
ID: 39704399
fantastic advice fyed, i'll use just that! thanks!! = ))
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

704 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