TextWidthHeight function

M

mackcawthon

This is a question for Stephen Lebans. I recently downloaded the
TextWidthHeight function from your web site. I am using it to bottom
justify text in a text box in the header of a user-customizable
report. The user enters a column heading for each column in a dialog
box. Then I put this text in the column heading and use your function
to bottom justify the text. I have tested the report with various
different text strings. All of my test strings worked fine until I
entered the following: "The effective date of the contract". When I
entered this string, the last line of the corresponding column heading
containing the word, "contract", was cut off. The heading looked like
this:
The
effective
date of the

There were no carriage returns in the string. Both the width and
height of the column heading control are .9717". The font is Arial
9pt bold. I use Access 2003.

At first I thought that I had made a mistake and had not implemented
your function correctly. So as a crosscheck, I went to the Customer
form in the database that I downloaded from your site. I changed the
width of the testmemo control to .9717 and Arial 9pt bold. I entered
the problematic text in that field. When I clicked "Turn on
Autosizing", the resulting height was 900, the total lines were 4, and
all four lines of text were shown in the testmemo field as expected.
Then I went to your Report1 report and made similar changes to the
testmemo control there. When I ran the report, the resulting height
was 648 and the total lines were 3. The last line of text in the
control was cut off just as in my own report. So there seems to be
some kind of issue with using TextWidthHeight in a report, at least in
this specific situation.
 
S

Stephen Lebans

As Access does not expose the logic/code it uses internally to render text
within a control my solution has to make a lot of assumptions regarding line
width, word breaks, hyphenation, border width etc. You'll notice the
solution contains a fudge factor. Simply increase the height of the control
slightly over what the function returns to ensure the last line is always
visible. I have found that with some fonts, Bolding or italics of text
causes problems with how Access calculates its word breaks.
Did you look at:
http://www.lebans.com/verticaljustification.htm
VerticalJustificationA2K.zip is a database containing a function to allow
for vertical centering of the contents of a Label or TextBox control. Works
with both Forms and Reports.



Finally, if you want absolute control then you must render the text yourself
via the report object's Print method. It's a lot of work when you are
fitting words to a defined space.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
M

mackcawthon

Thanks for your reply. I tried programmatically increasing the
control height (in the format event) as you suggested, but then the
bottom lines of my column headings don't line up after bottom
justifying. I also tried increasing the top margin of each control
slightly less than what the function would indicate, but again the
headings don't line up. I had already looked at
VerticalJustificationA2K.zip and based my procedure on that.

This is my original code called from the format event procedure,
before the modifications above:
Private Sub BottomAlign(ctl As Control)
Dim lngHeight As Long
Const csBotMargin As Long = 60 'bottom margin of column headings in
twips
'Find out the height of the text in the heading
lngHeight = fTextHeight(ctl)
If ctl.Height - lngHeight - csBotMargin > 0 Then
'Push the text down as needed by expanding the top margin
ctl.TopMargin = ctl.Height - lngHeight - csBotMargin
End If
End Sub
 
S

Stephen Lebans

I think you are going to have to try either using a different font size, or
as I suggested earlier, render the text yourself using the Text method of
the Report object.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 

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