text box on form - automatically adjust height based on contents

P

Paul Kraemer

Hi,

I am using Access 2007. I have a Textbox in the detail section of a form
that is bound to a field of type 'Memo'. Most of the time, this memo field
contains only one line of text. Sometimes, however, it contains several
lines of text. When designing the form, I made the height of this textbox
just high enough to display one line of text. This is ok for most records,
but for records where this field contains more than one line of text, I would
like the height of my Textbox to automatically increase in order to fit the
extra lines of text. I tried to do this by setting the "Can Grow" and "Can
Shrink" properties of both my Textbox and the Detail section itself to "Yes",
but this did not do anything.

Is there anyway that I can automatically adjust the height of my textbox to
accomodate the variable number of lines of text that it will contain from
record to record?

Thanks in advance,
Paul
 
D

Douglas J. Steele

Assuming you're talking a continuous form, be aware that changing the height
of the row will apply to every row in the form. You can take a look at what
Stephen Lebans has at http://www.lebans.com/cangrow.htm but be aware that it
hasn't been tested with Access 2007 yet.

The CanGrow property only applies text boxes and detail sections in Reports.
 
F

fredg

Hi,

I am using Access 2007. I have a Textbox in the detail section of a form
that is bound to a field of type 'Memo'. Most of the time, this memo field
contains only one line of text. Sometimes, however, it contains several
lines of text. When designing the form, I made the height of this textbox
just high enough to display one line of text. This is ok for most records,
but for records where this field contains more than one line of text, I would
like the height of my Textbox to automatically increase in order to fit the
extra lines of text. I tried to do this by setting the "Can Grow" and "Can
Shrink" properties of both my Textbox and the Detail section itself to "Yes",
but this did not do anything.

Is there anyway that I can automatically adjust the height of my textbox to
accomodate the variable number of lines of text that it will contain from
record to record?

Thanks in advance,
Paul

CanGrow and CanShrink, on a form control, will only work when/if the
form is Previewed or Printed.

I would suggest using the controls scroll bars. however, you might
want to see what is available at
http://www.lebans.com
 
D

Danny Seager

Well you could calculate how many characters you can fit on 1 line, some code
like the following should resize the control

Dim NoCanFit As Long ' The number of characters wide
Dim ChrHeight As Long ' The height 1 line in twips
Dim CtlHeight As Long
NoCanFit = 30
ChrHeight = 340

If Len(Me.YourControl & "") > 0 Then
Dim NoChar As Long
NoChar = Len(Me.Text0)

CtlHeight = ChrHeight * (Int(NoChar / NoCanFit) + 1)

If CtlHeight > ChrHeight Then
Me.YourControl.Height = CtlHeight
Else
Me.YourControl.Height = ChrHeight
End If
Else
End If
 
P

Paul Kraemer

Thanks Danny,

Where would be the best place for me to try that code? My guess would be
OnFormat, OnPaint, or OnPrint for my detail section?

Thanks again,
Paul
 
P

Paul Kraemer

Hi Danny,

When I sent my last post, I was mistakenly looking at the detail section of
a report when I asked you if I should put the code in the OnFormat, OnPaint,
or OnPrint event for my detail section? Now that I am looking at my form,
there only appears to be an OnPaint event. Does it make sense to try the
code here?

Thanks again,
Paul
 
D

Danny Seager

When do you expect/want it to resize?

I would put it in several places... inn for forms on current event so it is
resized when the record is loaded and probably in the forms after update
event.
 

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