By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,480 Members | 771 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,480 IT Pros & Developers. It's quick & easy.

Multi select listbox question...

P: n/a
I have a listbox set to simple multi select. For this example, users only
select one item at a time. I have command buttons on the form for First,
Previous, Next, Last, New (record). The form and listbox are unbound. The
listbox rowsource is a value list. The list box has about sixty items in
it. Each item in the list box corresponds to a record in the database.
When a user selects a row in the list box, the record is retrieved. The
same thing for if one of the command buttons is clicked. The problem is
that if I'm on the first record and I select the "Last" command button,
everything works fine except I can't see the highlighted last row of the
listbox. If I scroll down the listbox, the last row is correctly
highlighted, I just don't jump to it when "Last" is clicked.

My code is something like this: (Assume I'm on the first record then
clicking "Last"

MyListbox.Selected(1) = False
MyListbox.Selected(60) = True

How do I make the last row visible?

Thanks.

Matthew Wells
MW****@FirstByte.net

Nov 24 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Try setting the listboxes Value property to ItemData(x) where x is the
row you want to set.

On another note, you may want to set the MultiSelect prop for this
listbox to "None" if you are only using this listbox for record
navigation. There's no need to allow the user to select more than one
item in the listbox, and by extension, more than one record in the
recordset.

Also not clear on why you are using a "Value List" RowSourceType. If
you have a value in the list for every record in the table you're
drawing your records from, wouldn't it be more efficient to set the
RowSourceType to "Table/Query" and provide a RowSource?

Matthew Wells wrote:
I have a listbox set to simple multi select. For this example, users only
select one item at a time. I have command buttons on the form for First,
Previous, Next, Last, New (record). The form and listbox are unbound. The
listbox rowsource is a value list. The list box has about sixty items in
it. Each item in the list box corresponds to a record in the database.
When a user selects a row in the list box, the record is retrieved. The
same thing for if one of the command buttons is clicked. The problem is
that if I'm on the first record and I select the "Last" command button,
everything works fine except I can't see the highlighted last row of the
listbox. If I scroll down the listbox, the last row is correctly
highlighted, I just don't jump to it when "Last" is clicked.

My code is something like this: (Assume I'm on the first record then
clicking "Last"

MyListbox.Selected(1) = False
MyListbox.Selected(60) = True

How do I make the last row visible?

Thanks.

Matthew Wells
MW****@FirstByte.net
Nov 25 '06 #2

P: n/a
Doesn't work. The listbox has the correct value, it just doesn't move to
the highlighed record.

I have

LB.Value = sValue

The bound column is a string data type

Per your suggestion, I tried

With LB
.Value = .ItemData(.ListIndex)
End With

The resule is the same. No matter how the value is calculated on the right
hand side of "=", it's still assigning a string to the lb value property.

Per your comments:
If users only want to select one record at a time, they can. There are some
functions that users can do on multiple records - that's why it's
multi-select. If a user selects more that one record, most of the form
controls - (the navigation buttons and the fields in particular) become
disabled and only the command buttons that perform those functions mentioned
earlier remain enabled. The form is totally unbound, that's why the value
list. I could bind the lb to a disconnected recordset, but value lists
perform better.

I do thank you for your suggestion.
"Jamey Shuemaker" <ca*********@yahoo.comwrote in message
news:11**********************@h54g2000cwb.googlegr oups.com...
Try setting the listboxes Value property to ItemData(x) where x is the
row you want to set.

On another note, you may want to set the MultiSelect prop for this
listbox to "None" if you are only using this listbox for record
navigation. There's no need to allow the user to select more than one
item in the listbox, and by extension, more than one record in the
recordset.

Also not clear on why you are using a "Value List" RowSourceType. If
you have a value in the list for every record in the table you're
drawing your records from, wouldn't it be more efficient to set the
RowSourceType to "Table/Query" and provide a RowSource?

Matthew Wells wrote:
I have a listbox set to simple multi select. For this example, users
only
select one item at a time. I have command buttons on the form for
First,
Previous, Next, Last, New (record). The form and listbox are unbound.
The
listbox rowsource is a value list. The list box has about sixty items
in
it. Each item in the list box corresponds to a record in the database.
When a user selects a row in the list box, the record is retrieved. The
same thing for if one of the command buttons is clicked. The problem is
that if I'm on the first record and I select the "Last" command button,
everything works fine except I can't see the highlighted last row of the
listbox. If I scroll down the listbox, the last row is correctly
highlighted, I just don't jump to it when "Last" is clicked.

My code is something like this: (Assume I'm on the first record then
clicking "Last"

MyListbox.Selected(1) = False
MyListbox.Selected(60) = True

How do I make the last row visible?

Thanks.

Matthew Wells
MW****@FirstByte.net

Nov 25 '06 #3

P: n/a
Roger, the setup comments. Understood.

I'll have to play around with the selection stuff. I thought I had used
a similar process to select an item in a listbox on a form I use to
edit user groups, but it's possible that my list doesn't jump to the
desired position in the list either. I'll play around with that later,
and see if I can figure something out.

more later...

Nov 25 '06 #4

P: n/a
If the listbox is not a multiselect listbox you can set the selected
property of the last item in the list to true and the listbox will
scroll to that item. However, this doesn't work for multiselect
listboxes. You might try toggling off the multiselect property of the
listbox long enough to select the last record in the list and then
turning it back on again. You could also check out Stephen Lebans'
code here that may do what you need:

http://www.lebans.com/List_Combo.htm#ScrollListbox

HTH,
Bruce

Nov 27 '06 #5

P: n/a
That was interesting, but the .ListIndex property for Access listboxes is
read-only. I will try to toggle the multi-select.

Thanks.

Matthew Wells
MW****@FirstByte.et

<de***************@gmail.comwrote in message
news:11*********************@14g2000cws.googlegrou ps.com...
If the listbox is not a multiselect listbox you can set the selected
property of the last item in the list to true and the listbox will
scroll to that item. However, this doesn't work for multiselect
listboxes. You might try toggling off the multiselect property of the
listbox long enough to select the last record in the list and then
turning it back on again. You could also check out Stephen Lebans'
code here that may do what you need:

http://www.lebans.com/List_Combo.htm#ScrollListbox

HTH,
Bruce

Nov 28 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.