Make text boxes the same height

A

AnnieJ

I have 3 seperate text boxes that are side by side on a report, they vary in
height and can grow, I want to put a solid box around each but I want them
all to default to the tallest so as they look uniform when printed.
I have spent a long time looking at other posts and trying some OnPrint
event procedures but with no luck so far.
I hope someone can help, thanks in advance
 
S

Stockwell43

Open your report in Design View and right click on your textbox and open the
properties. Under the Format tab you will see a Width and Height field. These
are the fields to adjust your textbox.

If you hold down the shift key and click on each one to higlight them all
(or drag your mouse across all three) then right click on any of them open
the properties menu, and enter your dimensions and it will adjust all three
at the same time so you only have to do it once.
 
D

Duane Hookom

You need to use the Line method of your report to draw the rectangles around
your controls. Remove the borders of all text boxes and set their Tag
property to "Border". Then add code to the On Print event of the section
containing the can grow controls.

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
Dim intMaxHeight As Integer
Dim ctl As Control
'Find highest control in Detail section _
that has a tag property of "Border"
For Each ctl In Me.Section(0).Controls
If ctl.Tag = "Border" Then
If ctl.Height > intMaxHeight Then
intMaxHeight = ctl.Height
End If
End If
Next
'Draw a box around each control in Detail _
that has a tag property of "Border"
For Each ctl In Me.Section(0).Controls
If ctl.Tag = "Border" Then
Me.Line (ctl.Left, ctl.Top)- _
Step(ctl.Width, intMaxHeight), vbBlack, B
End If
Next
End Sub
 
A

AnnieJ

I have tried this before from another post of yours but have had no luck, I
have tried it again but still not working. What do you mean by "You need to
use the Line method of your report to draw the rectangles around your
controls.". Do you mean draw 4 lines around my text boxes to make a
rectangle? and how do I "remove the borders"? the rest I have got right I'm
sure.
 
S

Stockwell43

Annie,

If all you're looking to do is place a border around the field so when
veiwing the report the data shows in a black box go into the properties of
that text box and change the border width from Hairline to 1pt. or however
thick you want it. I also explained how to get them all the same size so you
should be good to go unless I am not getting what your asking for.
 
A

AnnieJ

(You may get this twice as the server broke as I posted last time)
You did miss the 'can grow' part. I have 3 boxes; Description,Qty,Price.
Description will grow but Qty and Price won't. I want Qty and Price boxes to
always be same height as Description.
Should be easy I thought, some days the obvious isn't so obvious though.
Hope you can help, thanks for your time so far.
 
S

Stockwell43

Yes, I did miss that I apologize for not being more attenative. I guess you
would use the code Duane is giving you. He has helped me out a lot and is
very knowledgable.

Open your report in design view I believe he means on each field go into the
properties and make sure your border style is transparent and border width is
hairline. Then scroll down to the Tag Property and type in Border. As for the
code, when you are looking at your report in design view, you should have the
standard Page Header, Detail, Page Footer and Report Footer provided you
didn't add any groups. Let's say your field that is set to "Can Grow" is in
the Detail section. Right click on the detail bar to open it's properties and
you will see the On Print event. Click on the drop down and select Event
Procedure, then click on the three dots to the right. Your vba code window
should open and that's where you want to place your code.
 
E

Evi

I think I see what is happening.
Annie, you have used the Properties box (or the formatting toolbar) for your
text toxes to make their BorderStyle Solid. You want the controls
(textboxes) to grow together so that the *effect* is 3 black boxes of equal
height with the correct writing in each.

Duane's suggestion will give this effect. Set the BorderStyle for each box
back to Transparant. With the Properties box open, click on each textbox,
click on the 'Other' tab in the Properties box and next to where it says Tag
type the word Border. Duanes code looks at all the controls in your report's
section and draws a box around any which have the word Border written in the
Tag section.

The bit of his code which says

'Draw a box around each control in Detail _
that has a tag property of "Border"

doesn't mean that you have to physically draw the boxes. It's a comment line
(that's why it starts with a '). It's put there to show you what that bit of
the Code is doing.

The code is put into a code page which (in Design View) you open by right
clicking on the grey bar above the section which contains the controls.
Click on Properties.
Click on the Events tab
Next to OnPrint choose Event Procedures. Open a Code page, Delete the lines
below 'Option Compare Database' which appear there automatically, and paste
in Duane's code (use his original posting so you don't have to delete >>>'s)

You'll see that any line which begins with a ' will be green in the code
window. It's not actually part of the code, it's there just to tell you what
is happening in the code.

When Duane says 'Use the Line method' he's referring to the bit of his code
that says
Me.Line
That's the bit which draws the boxes.

Do try it, it I'm sure it will work. If it doesn't tell us which line it
gets stuck on.

Evi
 
D

Duane Hookom

Stockwell43,
Thanks for further explaining how to implement the code.

AnnieJ,
You can set the properties of several controls at the same time by selecting
them all then entering the values. For instance click the first text box then
hold down the shift key and click other text boxes to select. You can then
view the properties and set the Tag to "Border" and border to transparent.
 
J

John G

Duane,
Your code works great. Just one thing. Is there a way to increase the size
of the line ?

Thanks.
John G
 
D

Duane Hookom

You can add a line of code to set the DrawWidth prior to looping through the
controls to draw the rectangles.

Me.DrawWidth = 6 'play with this number
 
A

AnnieJ

Yes, I had done all that.
It did dawn on me that I did something else very stupid/simple though, when
your original email said to type "Border" in to the Tag box that is what I
did. What I should have done was typed Border without the quotes. Now it
works perfectly as it should have done before. Sorry and thanks alot.
 
L

Lydia

Duane,

Your method of drawing rectangles to accomodate text box size growth worked
great for me too. Thanks.

One more question, how to fill one of the drawn boxes with color? Thanks.

Lydia
 
D

Duane Hookom

Here is some sample code. Note the "F" at the end of the line
'fill the description text box with yellow
Me.Line (Me.Description.Left, Me.Description.Top)-Step _
(Me.Description.Width, Me.Description.Height), vbYellow, BF
 
L

Lydia

I am sorry for my late response.

I tried it, but nothing happens.

Me.Line (ctl.Left, ctl.Top)- _
Step(ctl.Width, intMaxHeight), vbYellow, BF

Could you please see if something is wrong here?

Thanks.

Yingzi
 
D

Duane Hookom

Where exactly is the code running? Have you tried setting a break point and
stepping through the code?
 
L

Lydia

Yes!! After I set break point, I found out that I missed a pair of quotation
marks around the name of the control box I want to set color to. After I
added them, it worked beautifully. I then replaced the vbYellow with the
color code I want to set it to: 12632256, a kind of bluish grey, it works
great.

Thanks a lot.

Lydia
 
T

Tom Coon

I tried Duane's code and found that it did not work when printing. It works if I print preview, but not printing or saving as PDF.
 
D

Duane Hookom

I think you only need to set the DrawWidth of your report to make a thicker
line.

Me.DrawWidth =5
 

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