S
Sam
Is there a way to programmatically select the first row of a listbox?
Thanks,
Sam
Thanks,
Sam
Ken Snell MVP said:
<snip>Ken Snell MVP said:My suggestion works on a listbox regardless of the setting of the Multi
Select property.
My suggestion works on a listbox regardless of the setting of the Multi
Select property.
[quoted text clipped - 6 lines]Me.NameOfListBox.Value = Me.NameOfListBox.ItemData(0)
Dale_Fye via AccessMonster.com said:Yes,Ken, it will select the item, but if you do the following on a Multi-
Select = None listbox
Me.NameOfListBox.Selected(0) = True
msgbox me.NameOfListBox.Value
it will generate an error #94, Invalid use of Null
My suggestion works on a listbox regardless of the setting of the Multi
Select property.
[quoted text clipped - 6 lines]Me.NameOfListBox.Selected(0) = TrueMe.NameOfListBox.Value = Me.NameOfListBox.ItemData(0)
Ken Snell MVP said:Point taken, Dale. Thanks.
--
Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/
Dale_Fye via AccessMonster.com said:Yes,Ken, it will select the item, but if you do the following on a Multi-
Select = None listbox
Me.NameOfListBox.Selected(0) = True
msgbox me.NameOfListBox.Value
it will generate an error #94, Invalid use of Null
My suggestion works on a listbox regardless of the setting of the Multi
Select property.
Me.NameOfListBox.Selected(0) = True
[quoted text clipped - 6 lines]
Me.NameOfListBox.Value = Me.NameOfListBox.ItemData(0)
Mac said:Can you explain why this happens? I've been trying to select the first
item
in a listbox (multiselect = none) when users cancel a new listbox entry
routine (using Me.Undo). Although the first item appears to be selected,
other fields which depend on the listbox aren't being updated when I use
the
Selected(x) approach:
The statement:
Me.lstProblem.Selected(0) = True
MsgBox Me.lstProblem
generates a null, whereas the statement:
Me.lstProblem.Value = Me.lstProblem.ItemData(0)
MsgBox Me.lstProblem
displays the first entry on my listbox. I'm happy the latter statement
works, but am curious what I'm missing with the former. Thanks....
Ken Snell MVP said:Point taken, Dale. Thanks.
--
Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/
Dale_Fye via AccessMonster.com said:Yes,Ken, it will select the item, but if you do the following on a
Multi-
Select = None listbox
Me.NameOfListBox.Selected(0) = True
msgbox me.NameOfListBox.Value
it will generate an error #94, Invalid use of Null
Ken Snell MVP wrote:
My suggestion works on a listbox regardless of the setting of the Multi
Select property.
Me.NameOfListBox.Selected(0) = True
[quoted text clipped - 6 lines]
Me.NameOfListBox.Value = Me.NameOfListBox.ItemData(0)
Stuart McCall said:The Selected collection is available only for multi-select listboxes (or
at least that's how MS intended it). The ItemData(0) method is the way to
go with single-select boxes.
So you're not missing anything.
Apart from one little niggle (there's always something). If you set the
listbox's Column Heads property to Yes, item 0 contains the headers, so in
order to select the first data item you need to use an index of 1.
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.