Hi, I have a form field (6 column listbox) which is populated by a query. I would like the vertical height to grow as needed when additional rows are added.
The form isn't being closed, but it's re-queried after each new item is selected. Is this possible to do? I search the forum and came up empty.
Hi, I have a form field (6 column listbox) which is populated by a query. I would like the vertical height to grow as needed when additional rows are added.
The form isn't being closed, but it's re-queried after each new item is selected. Is this possible to do? I search the forum and came up empty.
Dim getListboxCount As Integer
Dim setHeight As Integer
count = Me.getListboxCount.ListCount
' Adjust Number Accordingly
setHeight = 217
Me.getListboxCount.height = count * setHeight
You can use an event to trigger the vba code. Basically, what I assumed is that on your requery, you wrote a little code to do that.
What it does is gets the count of how many records in your listbox and assign a variable to it. The getListboxCount is the name of your listbox
i.e.
count = Me.getListboxCount.listcount
I assigned a static number to a variable which would correspond to a height of 1 record in your listbox. The 217 can be adjusted to whatever number, but in my test for 1 record, 217 worked perfect
i.e.
setHeight = 217
Now what I did is dynamically assign the name of listbox with a height property and multiplied my variables to get my height of the listbox.
i.e.
Me.getListboxCount.height = count * setHeight
Thank you for explaining this for me. I tried this and i get the error "This property is read only and can't be set". Is this something I should be able to change?
Thank you for explaining this for me. I tried this and i get the error "This property is read only and can't be set". Is this something I should be able to change?
I think when I went back initially to give my variables a better description I gave you an erroneous variable. I should have tested before replying.
Look at this new code:
Code:
Dim getListboxCount As Integer
Dim setHeight As Integer
getListboxCount = Me.myListBox.ListCount
' Adjust Number Accordingly
setHeight = 217
Me.myListBox.height = getListboxCount * setHeight
So...let me correct my explanation again.
What it does is gets the count of how many records in your listbox and assign a variable to it (getListboxCount).
The "myListBox" is the name of your listbox.
The "listcount" is a property that gets the total records in your listbox.
i.e.
getListboxCount = Me.myListBox.listcount
I assigned a static number to a variable which would correspond to a height of 1 record in your listbox. The 217 can be adjusted to whatever number, but in my test for 1 record, 217 worked perfect
i.e.
setHeight = 217
Now what I did is dynamically assign the name of listbox with a height property and multiplied my variables to get my height of the listbox.
i.e.
Me.myListBox.height = getListboxCount * setHeight
Amazing! Thank you so much for helping. This works great...another one to keep in my book of tricks. Again, thank you for explain it...I understand what's happening