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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refreshing Form: How to move to top of ListBox with VBA

Status
Not open for further replies.

LaCour

MIS
Jul 15, 2004
53
0
0
US
I have form with many unbound controls; they are used to generate a filter for the subform when a "Search" cmd button is pressed. I also have a "Clear" cmd button that will reset all of the unbound controls and refresh the subform.

Everything is working fine. However, I have a couple of list boxes that don't move back to the top of the listbox. I am able to de-select those rows that are selected, but I am not sure how to move the listboxes to the top as it is / was when the form initially opens.

Thanks in advance
Blair
 
I think you can do like this?
Code:
lstMyListName.Item(0).Selected = True
or something like that..

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
That will select (highlight) the 0th entry in the listbox, but it does not bring focus to the top.

I am guessing this will have something to do with referencing the (0) location as you suggested. I'll mess with .setfocus but I think that is in regards to the control from the perspective

Let me know if any other ideas come to mind ...

Blair
 
I am sure that would work - the above example. Try it, if you have not tried it yet. It may seem too simple, but if it works, why not? I assume you want that to happen when the form loads? Also, the above does not referernce just the control, but rather the first item in the listbox control. If you want it to run when you form first comes up, just put it in the Form_Load() event.

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
And actually, the format is not exactly correct - I goofed. It should be:
Code:
lstMyListName.Selected(0) = True

try that! [wink]

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
Stephen

Both of your examples highlight / select the first item in the list box. I tried them both.

I found a simple explanation that works:
Me.lstKeyProcess1.RowSource = Me.lstKeyProcess1.RowSource


It also clears the list box ... I was doing the following (which I thought was efficient before)

For Each varItem In Me.lstKeyProcess1.ItemsSelected
Me.lstKeyProcess1.Selected(varItem) = False
Next varItem


Thanks for your help
 
Hmm, so you were not necessarily wanting to actually SELECT the first item, but just have the code pointing at the first item. If I'd of understood that, I could have given you that .rowsource = .rowsource part - even considered throwing it out there.. lol [lol] oh well... glad you got it fixed.

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top