Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

listbox always returns null though item is programmatically selected

Posted on 2013-12-08
4
Medium Priority
?
1,541 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
  • 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 49

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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

886 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