value property not updating after selection change in list box

jjmclell

Registered User.
Local time
Today, 05:07
Joined
Aug 10, 2009
Messages
22
Hi there,

I have a list box with a bunch of items in it. The user can select an item and hit a delete button to remove it which then causes some other things to happen. Basically, as part of that event, I need to select the next item in the list and return its value, as shown below:

Code:
[B]Form1!listOfItems.Selected(next) = True[/B]
[I]Do something with[/I] [B]Form1!listOfItems.Value[/B]

As far as I can tell from the help files, calling for the value property of a list box is supposed to return the value of the selected item; however, in this case it's returning the value of the previously selected item - the one that the user originally selected. The value property is not updating to reflect the change in selection in the list box. Any ideas?

jjmclell
 
What event are you trying to use this code in? Also, is this a single-select or multi-select listbox?
 
Ok, the event is just an On Click event. Here's what it's supposed to do:

The list box in question has a bound column that returns the name of an OLE object in a report. On clicking a button, the selected item in the list box returns the name of an OLE object in the report that is to be deleted. That works fine. However, before deleting the reference to the object from the list box, I want to cycle through each item after the deleted one and return its value (OLE object name) so that I can move each subsequent object in the report up to fill in the gap left after deleting the original object.

Code:
'set lstIndex = to the index of the selected value in the list
lstIndex = Form_Charts.lst_Charts.ListIndex
 
'set ctrl = to the next index in the list
      ctrl = lstIndex + 1
 
'while ctrl is less than the number of items in the listbox:
      Do While ctrl < Form_Charts.lst_Charts.ListCount
 
'select the item indexed by ctrl
        Form_Charts!lst_Charts.Selected(ctrl) = True
 
'and set its Top property = to 3.5 inches less
        Reports("chartRepTemplate")!Controls(Form_Charts.lst_Charts.Value).Top = Reports("chartRepTemplate").Controls(Form_Charts.lst_Charts.Value).Top - 3.5 * 1440
 
'increment ctrl to the next item 
        ctrl = ctrl + 1
      Loop
 
'finally remove the originally selected item from the listbox
  Form_Charts.lst_Charts.RemoveItem (lstIndex)

The problem is when I do this:

Code:
Form_Charts!lst_Charts.Selected(ctrl) = True

This doesn't change:

Code:
Form_Charts.lst_Charts.Value

The Multi Select property of the list box is set to None.

jjmclell
 
Ok, well I got the code working. I used

Code:
Form_Charts.lst_Charts.Itemdata(ctrl) [I]instead of [/I]Form_Charts.lst_Charts.Value

I swear I found a bug though. The value property is supposed to return the bound column value for the selected item in a listbox and if I programmatically changed the selection in the listbox, the value property didn't update. Oh well...
 
Again, is it a multi-select list box or a single-select list box? A single-select listbox will return a value, where a multi-select listbox always returns a NULL for the value property.
 
The multiselect property is set to none...I assume that means single-select (see very end of my 2nd post). It's not that the listbox wasn't returning a value...it was just returning the value of the previous selection.

jjmclell
 

Users who are viewing this thread

Back
Top Bottom