Programmatic Detail Height

W

WorldCTZen

I need to set the height of the detail, and all the controls on the detail,
based on the contents of a textbox.
I can't just set the textbox and detail to CanGrow = true, as this will
cause gaps in a grid when the other controls don't grow at the same time.
So, I have the following:
If Len(LineItemTxt) > 58 Then
Me.Detail.Height = 480
Me.LineItemTxt.Height = 480
Else:
Me.Detail.Height = 240
Me.LineItemTxt.Height = 240
End If
(I've taken out the other conrols, as they work appropriately with the above
code.)
The problem I'm having is that the Detail will grow when it shouldn't.
In a group, if there are any records where LineItemTxt has more than 58
characters, the first Detail in the group will grow, even though THAT record
doesn't have >58 chars. Then, on the second record, the detail will return to
240 twips, and on the records that do have more than 58 characters, the
Detail will size back up to 480 twips.

I've tried this with Detail.CanGrow set to both false and true, with the
same result.
If I don't set the Detail.Height value for each detail, it will grow to
480twips with the first record to have more than 58 chars, and stay that way.
So the logic setting it to 240 Twips works.. but somehow it's being
overwritten on the first record. The odd thing is the LineItemText field is
exactly the right height each time, so it's not the logic.. Some special
function of the Detail is at work here.. Any suggestions?
 
J

John Spencer

Try the following. Shrink the control height before you try to shrink
the section height.

If Len(LineItemTxt) > 58 Then
Me.Detail.Height = 480
Me.LineItemTxt.Height = 480
Else:
Me.LineItemTxt.Height = 240
Me.Detail.Height = 240

End If

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 
W

WorldCTZen

Bingo!
Order of procedure bites again.
Thank you for the solution.. That still leaves the question, why is it
expanding to begin with? The previous lines were still only 240twips high and
its contents are only 240twips.. It seems like the detail evaluates at the
beginning of a group what the maximum detail height within the group is, then
sets the detail to be that high beginning with the first detail. Is this an
intentional behaviour, or should I be looking in my code for something
causing this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top