Value given to a listbox via VBA is not available

johan_beemsterboer

New member
Local time
Today, 04:56
Joined
Jun 9, 2010
Messages
2
Dear all,

First of all, I'd like to thank you all for your expertise you share here. I've been here many times, and most of the times I do not need to look any further, because the answer is already on this forum. Thank you for that!

However, I'm struggling with a problem now where I can't find the solution for. So here it is:

I've got a form with a child form, a chart and a list box in it. When you select a value in the list box, the chart changes. In the child form, you can click on a hyperlink. The value you click on is transported to the list box as well. The chart is being generated based on the list box. However, when I click on the hyperlink, it selects the given value in the list box, but you can't read the value out of the list box with vba. I've tried refresh and repaint, but it doesn't transport the value to the list box completely. I think it can be done with the On Dirty property, but I'm nog familiar with that one.

Can anyone please help me?

Thanks in advance
 
Welcome to AWF!!! (as a registered member) :)

Not entirely sure what's going on there but there have been cases where the value property doesn't yield correct results in a multi-select list/combo box. Use the Column property instead. Look in the help files for a quick explanation on this property.

lstbox1.Column(0) - is the same as lstbox1.value
 
Actually, when multi-select is on there is no Value Property in a Listbox or Combobox (in 2070/2010) at all and you have to loop thru to find out what is selected, even if only one selection has been made.

As to the actual question poated by the OP, to be homest, I can't make heads or tails out of the scenario as explained!
 
Hmmm... I think you would find that there is. The value property is the value of the first/bound column of the highlighted row in the listbox. I'm almost certain about that. Although I Access at hand at the mo to test it.

Yes, it's not quite clear-cut what the OP wants.
 
Thanks for the quick replies!

A very simple example on what goes wrong:

listbox1.value = "hello"
msgbox listbox1

- Error - invalid use of null

In other words: I want to set the value of listbox 1 programmatically, and read the value in a later stage. Somehow, it can't be read. When I click on the selected value in listbox1, then the code works as it should... Still no clue!
 
Ah alright, you can set the value using your method if you use the value of the bound column. The bound column isn't necessarily the visible column. I imagine in your case the bound column is an ID of some sort? Maybe a number ID. So you must use that.

listbox1.value = 123456

For you to read the value you must programatically highlight it by using its Selected propert.

listbox1.Selected(0) = True

Now from that you will be able to get the value.
 

Users who are viewing this thread

Back
Top Bottom