Solved

listbox always returns null though item is programmatically selected

Posted on 2013-12-08
4
1,298 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 (Access MVP) 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Menus 6 57
Can not open the Access Help ? 3 40
Intermittent OleDbConnection Error 20 53
View SQL Count Records 3 32
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

751 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