Listbox .Selected=False won't work

R

Ronald

Hi.

In Access 2003 I have an unbound listbox with 2 columns. It's all standard,
no multiselect.
In the OnClick event of the listbox I use the 2 values in the columns and
then want to reset the selected row.
To do this I've tried:

Me![lstListbox].Selected(Me![lstListbox].ListIndex) = False

For Each varItem In Me![lstListbox].ItemsSelected
Me![lstListbox].Selected(varItem) = False
Next varItem

For lngRow = 0 To Me![lstListbox].ListCount - 1
Me![lstListbox].Selected(lngRow) = False
Next lngRow

but none of them work.
Why?
Please help.

Ronald.
 
R

Ronald

Thank you, Douglas.

No, that doesn't work (with or without my code). The selected row does flash
off and then on (selected) again.

Ronald.

Douglas J. Steele said:
Try:

Me![lstListbox].RowSource = Me![lstListbox].RowSource

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Ronald said:
Hi.

In Access 2003 I have an unbound listbox with 2 columns. It's all
standard,
no multiselect.
In the OnClick event of the listbox I use the 2 values in the columns and
then want to reset the selected row.
To do this I've tried:

Me![lstListbox].Selected(Me![lstListbox].ListIndex) = False

For Each varItem In Me![lstListbox].ItemsSelected
Me![lstListbox].Selected(varItem) = False
Next varItem

For lngRow = 0 To Me![lstListbox].ListCount - 1
Me![lstListbox].Selected(lngRow) = False
Next lngRow

but none of them work.
Why?
Please help.

Ronald.
 
D

Douglas J. Steele

Sorry, I've never seen that behaviour.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Ronald said:
Thank you, Douglas.

No, that doesn't work (with or without my code). The selected row does
flash
off and then on (selected) again.

Ronald.

Douglas J. Steele said:
Try:

Me![lstListbox].RowSource = Me![lstListbox].RowSource

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Ronald said:
Hi.

In Access 2003 I have an unbound listbox with 2 columns. It's all
standard,
no multiselect.
In the OnClick event of the listbox I use the 2 values in the columns
and
then want to reset the selected row.
To do this I've tried:

Me![lstListbox].Selected(Me![lstListbox].ListIndex) = False

For Each varItem In Me![lstListbox].ItemsSelected
Me![lstListbox].Selected(varItem) = False
Next varItem

For lngRow = 0 To Me![lstListbox].ListCount - 1
Me![lstListbox].Selected(lngRow) = False
Next lngRow

but none of them work.
Why?
Please help.

Ronald.
 
B

Branislav Mihaljev

Ronald said:
Hi.

In Access 2003 I have an unbound listbox with 2 columns. It's all
standard,
no multiselect.
In the OnClick event of the listbox I use the 2 values in the columns and
then want to reset the selected row.
To do this I've tried:

Me![lstListbox].Selected(Me![lstListbox].ListIndex) = False

For Each varItem In Me![lstListbox].ItemsSelected
Me![lstListbox].Selected(varItem) = False
Next varItem

For lngRow = 0 To Me![lstListbox].ListCount - 1
Me![lstListbox].Selected(lngRow) = False
Next lngRow

but none of them work.
Why?
Please help.

Ronald.

Hi,

Technically this is the same, but try this:

Dim strList As String
With Me.listboxName
strList = .RowSource
.RowSource = vbNullString
.RowSource = strList
End With

Regards,
Branislav Mihaljev
Microsoft Access MVP
 
L

Linq Adams via AccessMonster.com

Even simpler,

Me.lstListbox = Null

works just fine for me.
 
D

Douglas J. Steele

Don't think that works with multiselect lists, or if it does, it only works
with one type of multselect list
 
L

Linq Adams via AccessMonster.com

From the OP:
"It's all standard, no multiselect."

So it will work under this condition, with Multi-select set to No.

I'm sure you're right about Multi-select. If Multi-select is set to either
Simple or Extended, the Listbox essentially no longer has a Value property.
If you try using a standard assignment of

Me.SomeTextBox = Me.lstListbox.Value

in the AfterUpdate of a Listbox with Multi-select set to Simple or Extended,
you'll pop an error "Invalid use of Null" because the Listbox Value property
has no data.
 
A

AccessVandal via AccessMonster.com

Try to use the Dot

With Me.lstListbox
For Each varItem In .ItemsSelected
.Selected(varItem) = False
Next varItem

Using the Bang does not work. The Bang refers to an object that is not part
of the instance or property.
Hi.

In Access 2003 I have an unbound listbox with 2 columns. It's all standard,
no multiselect.
In the OnClick event of the listbox I use the 2 values in the columns and
then want to reset the selected row.
To do this I've tried:

Me![lstListbox].Selected(Me![lstListbox].ListIndex) = False

For Each varItem In Me![lstListbox].ItemsSelected
Me![lstListbox].Selected(varItem) = False
Next varItem

For lngRow = 0 To Me![lstListbox].ListCount - 1
Me![lstListbox].Selected(lngRow) = False
Next lngRow

but none of them work.
Why?
Please help.

Ronald.
 
L

Linq Adams via AccessMonster.com

AccessVandal said:
With Me.lstListbox
For Each varItem In .ItemsSelected
.Selected(varItem) = False
Next varItem

Here again, Multi-Select is set to No, so there's really no need to loop thru
the items to set all that are selected to False, because only one can be
selected.

Me.lstListbox = Null

has been tested, using the OP's scenario and functions as desired.
 
D

David W. Fenton

Try:

Me![lstListbox].RowSource = Me![lstListbox].RowSource

I thought the problem was changing the selected value? All this will
do is re-assign the RowSource, which will lose any selection.
 
A

AccessVandal via AccessMonster.com

That not correct Adam.

The listbox is unbound to any value, so the value by default would be "Null".
In this basic scenario in your suggested code will work.

Somehow I do not wish to mislead the OP and beginners that this is the
solution. The OP wanted to unselect the list. What if the OP decide to use
the "Me.LstListbox.Selected" with extend or simple and pick the data from
user interaction?
 
Top