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

Need Listbox to Select First Record on Refresh/Requery

Status
Not open for further replies.

Fattire

Technical User
Nov 30, 2006
127
US

I just need a list box to always go to the top row no matter what was previously selected in the list box.

Me.Refresh/Repaint/Refresh don't do anything and any population from SQL doesn't reset the last value chosen.

Minor thing, but its still rather annoying. Any help is appreciated.
 
Me.List = Me.List.Column(me.list.boundcolumn, 1)
 
This is cool PWISE, I wouldn't have thought of that...

Unfortunately the list box does not refresh itself to the top - even though the first value in the list box is selected. The scroll bars just stay where they were on the previous search. Any way to move the scroll bar to the top record?

Let me show the code to make sure I'm not conflicting with the natural functionality in any way.

Code:
    Me.lst_MainSearch.RowSource = sqlstr1
    Me.lst_MainSearch = Me.lst_MainSearch.Column(Me.lst_MainSearch.BoundColumn, 1)
    DoCmd.Hourglass False
 
Have you tried the listindex property.

Me.Listx.Setfocus
Me.Listx.listindex=0

 
Thanks for the help guys! How do you learn all this stuff?

This worked...I could have sworn I looked at that in help but I missed it. The listbox is unbounded btw.

Code:
    Me.lst_MainSearch.SetFocus
    Me.lst_MainSearch.ListIndex = 0
[\code]
 
Glad it worked. It might also be good to precheck the listcount of the list is greater than 0, otherwise it will generate an error.

if Me.lst_MainSearch.listcount>0 then
Me.lst_MainSearch.SetFocus
Me.lst_MainSearch.ListIndex = 0
end if

Regards
 
Fattire . . .

and this:
Code:
[blue]   Me.lst_MainSearch.RowSource = Me.lst_MainSearch.RowSource [green]'Requery[/green]
   Me.lst_MainSearch.Selected(0) = True[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 


Very nice.... this is all good programming and I've put it into prod, thanks again!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top