Solved

listbox always returns null though item is programmatically selected

Posted on 2013-12-08
4
1,117 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 250 total points
Comment Utility
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
Comment Utility
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 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 250 total points
Comment Utility
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
Comment Utility
fantastic advice fyed, i'll use just that! thanks!! = ))
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now