Allowing listbox to grow vertically.... (1 Viewer)

sailorguy

Registered User.
Local time
Today, 14:22
Joined
Jan 31, 2008
Messages
48
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.
 

accessNator

Registered User.
Local time
Today, 14:22
Joined
Oct 17, 2008
Messages
132
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.

Can you use vba code?

Code:
Dim getListboxCount As Integer
Dim setHeight As Integer

count = Me.getListboxCount.ListCount
' Adjust Number Accordingly
setHeight = 217 

Me.getListboxCount.height = count * setHeight
 

sailorguy

Registered User.
Local time
Today, 14:22
Joined
Jan 31, 2008
Messages
48
Hi, this is possible but I'm not too familiar with coding. Can you tell me basically what this is doing? I will try to adapt it to work.
 

accessNator

Registered User.
Local time
Today, 14:22
Joined
Oct 17, 2008
Messages
132
Hi, this is possible but I'm not too familiar with coding. Can you tell me basically what this is doing? I will try to adapt it to work.

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

Hope this made sense.
 

sailorguy

Registered User.
Local time
Today, 14:22
Joined
Jan 31, 2008
Messages
48
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?
 

accessNator

Registered User.
Local time
Today, 14:22
Joined
Oct 17, 2008
Messages
132
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

Hope this helps.
 

sailorguy

Registered User.
Local time
Today, 14:22
Joined
Jan 31, 2008
Messages
48
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:)
 

Users who are viewing this thread

Top Bottom