Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access VBA code listbox to deselect and bring to the top

Status
Not open for further replies.

jknuep

Programmer
Aug 7, 2007
3
US
I am trying to have a listbox programmatically unselect an item and then scroll all the way to the top.
I tried
Private Sub bringToTop()
Me.lstParts.Selected(1) = True
Me.lstParts.Selected(1) = False
End Sub
But it only works when I have it triggered from a cmd button. It does some funny stuff when I “call” it as part of an onClick event from another listbox; like being unable to select an item at all in the “lstParts” listbox. Any ideas as to why this happens or a better way to go about this???
 
There is something a little odd about listboxes. You need:

[tt]Me.lstParts.RowSource=Me.lstParts.RowSource[/tt]
 
That doesn't seem to do anything... The selected row remains selected.
 
And this (provided the listbox is NOT multiselect) ?
Me!lstParts.SetFocus
Me!lstParts.ListIndex = 0


Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
No, it’s not multiselect.
I tried the

Me!lstParts.SetFocus
Me!lstParts.ListIndex = 0

Which works fine when called from a cmd button, but not when calling it from an onclick event from another listbox. I get this error

“Run-time error ‘7777’
You’ve used the ListIndex property incorrectly.”

What seems to be happening, and I can’t explain it, is that the code seems to get triggered run. Any more ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top