Dynamic Form and List box height to prevent scroll bar from appearing

Rx_

Nothing In Moderation
Local time
Today, 06:31
Joined
Oct 22, 2009
Messages
2,803
Need a Form and the listbox (read only) to automatically grow in height to display all records without the scrollbar showing up in the listbox.

A short pop-up form uses an argument to open. The form has some header information on top and a Listbox on the bottom.

The form only needs to be Tall enough (height) to keep the Listbox from truning on the scroll bar. The List box typically has 4 to 16 records (readonly)

If the form opens with 0 to 4 records, the listox can default to a height to show 4 records.
If the form opens with more than 4 records (lets say 12 records), both the form and the list box need to grow in height, to prevent the scroll bar from appearing.

I use to do this in VB6 years ago. Thought somone might recommend some code or method to achieve this.
 
I've never tried to do this and am not sure what the purpose of such height adjustment would be, but it seems like the most straightforward approach to this would be to check the number of items that should appear in the list box and then create the form dynamically in code as needed, with height set appropriately to item count returned.
 
Hmm, have you considered using a Report as the pop-up? Sounds like that could give you what you want.
 
Thanks for the inputs! Think I iwll have the new hire try this:
dblFontSizeFactor = 0.15 ' variable for default font Tahoma 8
Me.TheListBoxName.Height = TheListBoxName.ListCount * (dblFontSizeFactor * 1440) ' Check this size and set some Max value in cae of runaway query.

The 0.15 would have to be adjusted by trial and error if a different font or size is used

Most likely need to set a Max height just in case some wild query returned thousands of records. Set the max height and let the scroll bar take it on the chin.

Also found this at: http://www.access-programmers.co.uk/forums/showthread.php?t=185977

Code:
Dim getListboxCount As Integer
Dim setHeight As Integer
getListboxCount = Me.myListBox.ListCount' Adjust Number Accordingly
setHeight = 217
Me.myListBox.height = getListboxCount * setHeight


Form Resize:
http://www.rogersaccesslibrary.com/forum/form-resize_topic546.html
Found this with downloads included
 
Looks like that ought to do it! Thanks for following up with your solution.
 

Users who are viewing this thread

Back
Top Bottom