variable height listbox

C

Chris_h

On my reports I usually set text boxes to a nominal height (depending on
font-size) and use the 'can grow' property to accommodate several lines of
text as required. I also have a list-box on the report and am having trouble
achieving the same effect. I can't find a 'can grow' property for the list
box so any alternative methods would be great.

Many thanks,

Chris
 
D

Douglas J Steele

The "can grow" property applies to individual lines of text. Since a listbox
cannot have more than one line of text per entry, it doesn't make sense to
have a "can grow" property for it.

If what you're trying to do is increase the number of rows that can be seen
in the listbox, you must adjust the listbox's Height property. To have its
height depend on the number of entries in it, you can use code like:

If Me.MyListBox.ListCount < 5 Then
Me.MyListBox.Height = 0.5 * 1440
Else
Me.MyListBox.Height = 1.0 * 1440
End If

Here, I'm setting the height to half an inch if there are fewer than 5 items
in the listbox, or to one inch if there are 5 or more items. (the 1440 is
because the property needs to be expressed in terms of twips when you're
setting it programmatically, and there are 1440 twips in an inch)
 
J

Jeff Boyce

Chris

I'm curious why you would use a listbox to display a variable number of
"rows" in a report.

Have you looked into using a subreport embedded in your main report? Have
you considered using the Detail section to list the variable number of rows?

Without more description of your data/relationships and what you're trying
to accomplish, these are only notions, and may not relate to your situation.

Regards

Jeff Boyce
<Access MVP>
 
C

Chris_h

Thanks for the responses. I have a list of 'research areas' which are
associated with an 'idea'. This is a many to to many relation so I have a
linking table. I then want to put all of the selected areas for a given idea
on the report for the ideas. I'm not really sure how I might do this with a
subreport - I used a listbox as that's what I had used on the Form!

Doug's answer looks like what I'm after. Where should I put that code?
OnFormat Detail would have been my guess but please correct me if that's
wrong!

Thanks again,
Chris
 
D

Douglas J Steele

Depends on the design of your application.

Assuming that the number of items in the listbox can change with each record
on your form, the Form's Current event would probably be the most
appropriate.
 
C

Chris_h

I may not have made myself clear. The list box is on a report not a form. I
assume I have to use a report event to format it!

Thanks,
Chris
 
D

Douglas J Steele

In my opinion, using a listbox doesn't make sense on reports. Listboxes are
intended to be an interactive control that allows a user to select one (or
more) items from a number of choices.

I'd recommend using a subreport rather than a listbox: it will automatically
grow appropriately.
 
Top