Full Version: Setting Listbox Height Gets Overflow Error
UtterAccess Forums > Microsoft® Access > Access Forms
nbeauchemin
Hi

I have code that multiplies the number of items in a listbox by 300 twips to set its height property when the user clicks on a command button. I keep getting Run time error 6 Overflow. Here's the code:

CODE
[/code]Private Sub cmdProjectServices_Click()
'This sub makes lstProjectServices visible and allows it to grow so you can see all of the choices at once.
'It gets the count of items in the list box and multiplies that count by the height of one item.
Me.lstProjectServices.Enabled = True

Dim getListboxCount As Integer
Dim setHeight As Integer
lstProjectServices.Visible = True

getListboxCount = Me.lstProjectServices.ListCount
' The below is the approximate height of a single row in twips
setHeight = 300
Me.lstProjectServices.Height = getListboxCount * setHeight
Me.lstProjectServices.SetFocus
End Sub[code]


The debug window highlights Me.lstProjectServices.Height = getListboxCount * setHeight when the error occurs.

I tried declaring getListboxCount and setHeight as Long, but got the same error.

There are 9 choices in the listbox, resulting in a height of 2,700 twips. I can set this height using VBA with no problem, but when I use this code to calculate it, it doesn't work.

If someone could tell me how to fix this, I'd be grateful.

Thanks!
theDBguy
Hi. What is the actual value when you step through your code? Can the form physically accommodate the increase in height?
nbeauchemin
Thanks!

My RowSource for the listbox gave way more items than I had expected. I changed the RowSource and it now works.
theDBguy
Hi. You're welcome. Glad to hear you got it sorted out. Good luck with your project.
missinglinq
FYI, as to the reason: Height takes a positive Integer, so the limit is 32,767; at 300 TWIPS a pop, a RowSource returning more than 109 Rows is going to exceed this limit, hence the Overflow Error.

Linq ;0)>
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.