flakey "Select All" behaviour on list boxes

D

Dirk Goldgar

ace said:
Win XP, Office 2003

I am changing the contents of a table driving a list box and then
selecting every item in the list box. (code shown below)
I am getting very flakey results with the highlighting - particularly
when going from more items, to less - highlighting where there are no
records, the "fewer case" records are not highlighted, etc.

Tried obvious things like removing all highlighting first, removing
the row source of the list box and then reapplying it.

Does anyone know how to do a a really cleansing reset on a list box ?

Many thanks in advance
Tony Epton



BuildTmpTaskDetail 'build the table that drives listbox
Me.lstTasks.Requery 'requery the list box
LstSelection Me.lstTasks, True 'select every item in the list box



Sub BuildTmpTaskDetail()
'----------------------------------------
'Build tmpTaskDetail based on selections
'made in the lstTaskType list box
'(another list box)
'-----------------------------------------
'
DoCmd.SetWarnings False
DoCmd.OpenQuery "qdelTmpTaskDetail"
DoCmd.OpenQuery "qappTmpTaskDetail"
DoCmd.SetWarnings True
End Sub



Sub LstSelection(ctlSource As Control, boolSelect As Boolean)
'
'-------------------------------------------
'Select or deselect every item in a list box
'
'-------------------------------------------
'
Dim intCurrentRow As Integer

For intCurrentRow = 0 To ctlSource.ListCount - 1
ctlSource.Selected(intCurrentRow) = boolSelect
Next intCurrentRow

End Sub

Can we assume that you tried this:

LstSelection Me.lstTasks, False 'deselect every item in the list
box
BuildTmpTaskDetail 'build the table that drives listbox
Me.lstTasks.Requery 'requery the list box
LstSelection Me.lstTasks, True 'select every item in the list box

?

I've always cleared all selections with code like this:

Dim varI As Variant

With Me.lstMyListbox

For Each varI In .ItemsSelected
.Selected(varI) = False
Next varI

End With

But I don't see offhand why your sub wouldn't work.
Tried [...] removing
the row source of the list box and then reapplying it.

So you did something like this?

Me.lstTasks.RowSource = ""
Me.lstTasks.RowSource = "YourRowsourceQuery"

I would expect just assigning the list box's rowsource to itself would
do double duty of clearing the selection and requerying the list bos:

Me.lstTasks.RowSource = Me.lstTasks.RowSource

That doesn't work?

Could it be a timing/synchronization problem with the delete and append
queries? Does it come out right if you step slowly through the code,
rather than just letting it run?
 
T

Tony Epton

Win XP, Office 2003

I am changing the contents of a table driving a list box and then
selecting every item in the list box. (code shown below)
I am getting very flakey results with the highlighting - particularly
when going from more items, to less - highlighting where there are no
records, the "fewer case" records are not highlighted, etc.

Tried obvious things like removing all highlighting first, removing
the row source of the list box and then reapplying it.

Does anyone know how to do a a really cleansing reset on a list box ?

Many thanks in advance
Tony Epton



BuildTmpTaskDetail 'build the table that drives listbox
Me.lstTasks.Requery 'requery the list box
LstSelection Me.lstTasks, True 'select every item in the list box



Sub BuildTmpTaskDetail()
'----------------------------------------
'Build tmpTaskDetail based on selections
'made in the lstTaskType list box
'(another list box)
'-----------------------------------------
'
DoCmd.SetWarnings False
DoCmd.OpenQuery "qdelTmpTaskDetail"
DoCmd.OpenQuery "qappTmpTaskDetail"
DoCmd.SetWarnings True
End Sub



Sub LstSelection(ctlSource As Control, boolSelect As Boolean)
'
'-------------------------------------------
'Select or deselect every item in a list box
'
'-------------------------------------------
'
Dim intCurrentRow As Integer

For intCurrentRow = 0 To ctlSource.ListCount - 1
ctlSource.Selected(intCurrentRow) = boolSelect
Next intCurrentRow

End Sub
 
T

Tony Epton

Can we assume that you tried this:

LstSelection Me.lstTasks, False 'deselect every item in the list
BuildTmpTaskDetail 'build the table that drives listbox
Me.lstTasks.Requery 'requery the list box
LstSelection Me.lstTasks, True 'select every item in the list box
Of course !
Brilliant !

I was clearing the selections after changing the contents of the
listbox, not before changing ie :

BuildTmpTaskDetail 'build the table that drives listbox
Me.lstTasks.Requery 'requery the list box
LstSelection Me.lstTasks, False 'deselect every item in the list
LstSelection Me.lstTasks, True 'select every item in the list box


Moving that one line of code to the very beginning makes all the
difference

Many thanks
Tony Epton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top