Grow, Expand, or Shrink a List Box

G

Guest

I want my list box to automtically expand to fit all controlled input. I do
not want a scroll bar.

1) Is it possible?
2) If so how?
 
G

Guest

Just set the number of available rows to display in the properties of the
list box to more than the amount of data in the list.


However, if u have lots of rows, the arrows will still appear i think
 
G

Guest

Hi,

When I saw the other reply (by Patrick) I was led down the path that he
followed - I also thought you were asking about rows in a combo box (dropdown
box, whatever); if that is your question, then if you're OK with VBA then the
following should work:

With the form in design view, go to the events 'page' of the properties
window and create a new subroutine in the 'on open' event. (Or, if there's
already an 'on open' event, add this code to it)

select case dcount("*", <queryname>)
case >8
me!<listname>.ListRows = dcount("*",<queryname>)
case else
me!<comboname>.ListRows = 8
end select

Needless to say, you replace <queryname> with the name of the query (or
table) that populates it (in double quotes) and <comboname> with the name of
the combo box.

If it is a LIST box that you're asking about (a fair assumption since that's
what you asked in the first place!) then it's not so simple. You'd actually
need to programatically open the form in design view, use the same DCount
formula to derive the number of rows, and then set the height of the list box
as something like
Height = (no. of rows * X) + Y
where X is the height needed for each row of data (which of course depends
on the font etc) and Y is the extra bit needed for top & bottom. And I think
you'd need to calculate it in 'twips' rather than inches or centimetres! (I
think there are 7200 twips per inch but I'm not sure; my VBA help isn't
telling me!) Then you'd reopen the form in form view. And don't put this
process into the 'on open' event as i think you'd go into an infinite loop -
instead, put it into the event that opens the form.

Of course you'd also need to ensure that there are no other controls below
the list box as they'd get hidden if the list grows too much. Plus of course
there's an absolute maximum form height of just under 56 cm.

Does this help? Please let me know - it's my first reply (I only signed on
yesterday with a question of my own)

All the best,
 

Ask a Question

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.

Ask a Question

Top