Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I make a rectangle resize around a 'can grow' text box?

Status
Not open for further replies.

tedmillerx

Programmer
Jan 6, 2001
52
US
I have a report that contains several text boxes. Some of these text boxes have an image that goes with them. Right now the report is designed so that whenever there is an image, a rectangle appears behind both the text and the image. The length of the text varies, as does the font size, which is determined by a drop down list in a form. Here's the code I'm using. 'PictureBox' is the image, 'txtName' is the textbox.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

Dim PrintForm As String
PrintForm = "Print Out"

If PictureBox.ImageBytes > 0 Then
PictureBox.height = 1000
Me.Detail.height = 1500
Me.Rectangle01.Visible = True
Me.Rectangle01.height = 1750
PictureBox.BorderWidth = 1

Else
PictureBox.height = 10
PictureBox.BorderWidth = 0
Me.Rectangle01.Visible = False
Me.Rectangle01.height = 10
Me.Detail.height = 500
End If

Me.txtName.FontSize = [Forms]![Print Out]![cmbRecipesFontSize]

This worked nicely before I made the font size variable - always had my block of text and image with a rectangle neatly around it. The problem - if a larger font size is selected, the textbox grows, the image (positioned below the textbox) is pushed down and out of the rectangle. I could make the rectangle bigger, but then if a smaller font size is used I wind up with a lot of empty space in the rectangle. So the question is - can I make that rectangle grow with the text box? I've found that I can get the rectangle to match the size of the textbox plus the image, thus:

Me.Rectangle01.height = Me.txtName.height + Me.PictureBox.height

- but this only sets the rectangle to the default textbox size as it is set in properties, and doesn't recognize that the textbox grows and shrinks. So what do I need to tell it to make it understand the can grow/can shrink factor? Any help would be MUCH appreciated. Sorry for the lengthy post.
 
You can get the "grown" height in the On Print event of the report section. This is too late the set the height of any control. You will need to use the Line method to draw the rectangle.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Thanks for the reply. I'm kind of a novice, obviously, so bear with me. When you say I can get the height in the On Print event, do you mean that I can write code that will somehow refer to the On Print command and set the size of the rectangle from there? How would I phrase that?
Why and how do I use the Line method to draw a rectangle?
(I've tried not to be vague.)
 
If you look at the event properties of a section, you will find the On Print event. Go into the module of this event and you can write code to find the height of a grown control
Code:
  dim lngHeight as Long
  lngHeight = Me.txtName.height
The Line method can be used during this code to draw lines or rectangles.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top