how to autoscroll a listbox

  • Thread starter Thread starter AccessFan
  • Start date Start date
A

AccessFan

I have a search box (text box) where a user can search
for a last name that's on the list of about 200 names
(listbox). My code can search it just fine but if
the "found" item was all the way in the bottom, you still
need to manually scroll down just to see the selected
item. I want to set the list box, though, in such a way
that when you search for an item in the list box,
the "result" will autoscroll so that you can see it right
away. Please help.
 
Why not use a combo box instead of a listbox? It's already designed to do
exactly what you want the listbox to do. Listboxes should be used for short
lists that don't require lots of scrolling, for exactly the reason you
posted.
 
When you set the ListBox control's Value property to that returned by
your search function then the control should automagically scroll to
bring the selected row into view.

If for whatever reason you do not want to set the ListBox control's
Value prop but still want to bring a specific row into view see:
http://www.lebans.com/List_Combo.htm#ScrollListbox
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
Stephen,

This came pretty close to answering a question I had. One
thing - why doesn't setting the listbox's value control
activate the AfterUpdate event? I'm actually setting the
value based on a control on another form. I can get the
form to open with the right listbox value selected, but
it's not then triggering the AfterUpdate, which looks up
that value's info on the subform. Any thoughts?
 
As noted in Help files, setting the value of a control via VBA code or via
macro *does not* cause the AfterUpdate event to occur. It is by design. If
you want that event's code to run, then call the AfterUpdate subroutine for
the control in your code when you want it to run.
 
Sounds straight-forward enough. Thanks, Ken
-----Original Message-----
As noted in Help files, setting the value of a control via VBA code or via
macro *does not* cause the AfterUpdate event to occur. It is by design. If
you want that event's code to run, then call the AfterUpdate subroutine for
the control in your code when you want it to run.

--

Ken Snell
<MS ACCESS MVP>




.
 
Anne said:
I take it back. How do I call the subroutine from another
form's control?


Assuming you are setting the control's value with a line of
code something like:

Forms!otherform.controlname = something

then you can call the control's AfterUpdate event procedure
this way:

Forms!otherform.controlname_AfterUpdate

You will probably have to change the control's AfterUpdate
procedure from Private to Public.
 
Or, assuming that all the controls are on the same form,

Call ControlName_AfterUpdate()
 
Back
Top