Listbox "Remembering" Selections???

  • Thread starter Thread starter JP
  • Start date Start date
J

JP

Running Access 2003 under XP Professional (problem also occurs w/ A2000
under XP Home).

My form has 2 listboxes: lbxCompanies and lbxDivisions. Both have
mutiselect = no

Clicking on a company in lbxCompanies dynamically requeries the Rowsource
for lbxDivisions so that only divisions of the selected company are showing.
This all works fine.

HOWEVER, lbxDivisions seems to "remember" which division was highlighted for
a given company, and re-highlights that division if I leave that company and
again come back to it.

For example, I click on Company A and then click on Division A2 (one of the
divisions of Company A). I thing click on Company B (which brings up the
divisions of Company B). I then click on Company A again. This brings up
the divisions of Company A (as it should), but Division A2 is again
highlighted even though the user has not yet selected a division.

Also, if I've selected the nth item in the list, debugging shows the
listindex as n-1 (consistent with the documentation), but it's .selected(n)
that shows as true and .selected(n-1) as false. According to the
documentation, .selected is 0 based just like listindex, so shouldn't it be
..selected(n-1) that's true?

Any thoughts?

Thanks in advance.
 
JP said:
Running Access 2003 under XP Professional (problem also occurs w/
A2000 under XP Home).

My form has 2 listboxes: lbxCompanies and lbxDivisions. Both have
mutiselect = no

Clicking on a company in lbxCompanies dynamically requeries the
Rowsource for lbxDivisions so that only divisions of the selected
company are showing. This all works fine.

HOWEVER, lbxDivisions seems to "remember" which division was
highlighted for a given company, and re-highlights that division if I
leave that company and again come back to it.

For example, I click on Company A and then click on Division A2 (one
of the divisions of Company A). I thing click on Company B (which
brings up the divisions of Company B). I then click on Company A
again. This brings up the divisions of Company A (as it should), but
Division A2 is again highlighted even though the user has not yet
selected a division.

Also, if I've selected the nth item in the list, debugging shows the
listindex as n-1 (consistent with the documentation), but it's
.selected(n) that shows as true and .selected(n-1) as false.
According to the documentation, .selected is 0 based just like
listindex, so shouldn't it be .selected(n-1) that's true?

Any thoughts?

Thanks in advance.

Are these bound listboxes? If so, requerying the list box isn't going
to change the value of the field to which it's bound, even if that value
is no longer present in the control's list of items. The behavior you
describe is consonant with lbxDivisions being bound to a field in your
form's recordsource.

About the ListIndex/Selected question: does the list box have its
ColumnHeads property set to Yes?
 
Dirk,

Thanks for your response.

These are unbound listboxes, so it would seem to me that they should not be
"remembering" anything.

As for the Listindex/Selected ... the column head property is Yes, I forgot
about that in counting the rows for the Selected property.
 
JP said:
Dirk,

Thanks for your response.

These are unbound listboxes, so it would seem to me that they should
not be "remembering" anything.

Now that I think about it, what I said about the value of the list box
would apply even for unbound list boxes. The control's Value property
is unchanged by requerying its rowsource. If you want to clear the
value of the list box, set its value to Null when you modify or requery
its rowsource.
 
Duh ... why didn't I think of that!!!

Thanks.


Dirk Goldgar said:
Now that I think about it, what I said about the value of the list box
would apply even for unbound list boxes. The control's Value property
is unchanged by requerying its rowsource. If you want to clear the
value of the list box, set its value to Null when you modify or requery
its rowsource.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Back
Top