Solved

listbox always returns null though item is programmatically selected

Posted on 2013-12-08
4
1,371 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 250 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 250 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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

617 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