Lebans modTextHeightWidth not working for me

G

Guest

I am trying to use the fTextHeightWidth method to expand the height of a row
of controls to the that of the largest control.

I use the fTextHeight method to get the number of lines needed for the value
in the textbox controls (see sample code below). This works most of the time
but it occasionally under estimates the total number of lines needed. When
this happens the control is incorrectly sized to its contents.

I tried using the print lines module as an alternate, but I need to
conditionally change the background colors of some of the controls and with
lines drawn the controls will not necessarily have the appropriate height for
the correspnding section in the grid to appear completely filled.

1. Has anyone had a similar problem with fTextHeight? Any recommendations on
fixing it?
2. Any idea how I can set the background color for a single section of a
grid created by print lines?



Sample Code:
Dim lngWidth7 As Long, lngHeight7 As Long, lngTotalLines7 As Long, lngRet7
As Long
lngRet7 = fTextHeight(controlName, , lngHeight7, lngWidth7, lngTotalLines7)

heightOfCell = 270
multiplier = 1

If multiplier < lngTotalLines7 Then
multiplier = lngTotalLines7
End If

total = heightOfCell * multiplier

Dim CtlDetail As Control
For Each CtlDetail In Me.Section(acDetail).Controls
With CtlDetail
If CtlDetail.Visible Then
CtlDetail.Height = total
End If
End With
Next
 
S

Stephen Lebans

If this is for a report then just use the Print event of the relevant
section to perform all of the desired modifications to the controls and to
draw the desired Lines, Borders etc..

--

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

Guest

It is for a report, and I am using the print event (as per your 'DrawGrid'
sample report). But I am encountering a problem where the lines look good
when I preview them in Access but then they disappear or appear disjointed
when I export to .pdf.

This is especially a problem since I draw a filled rectangle in one grid
section, so that it will appear as if the background color in a specific cell
is filled.

Neither of these problems would apply with the modTextHeightWidth module,
are there any known bugs in the function, or am I using it incorrectly?


Danae.
 
S

Stephen Lebans

There are no bugs in my code but it is only an approximation as Access
ultimately has the final say when it comoes to Section breaks, page Breaks,
CanGrow/Shrink issues etc.
I do not understnad exactly what you are trying to do. Could you explain it
again in more detail?

--

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

Guest

I am trying to format data into a report that looks alot like an excel
spreadsheet.
Data is displayed in 1pt bordered rows and some cells have the text of
background color change, depending on the data value contained.

To maintain even borders across textboxes of different height, I am using
your modTextHeightWidth function.

Unfortunately sometimes it returns the incorrect number of lines
corresponding to the text value expected for a textbox. The approximation
works well most of the time, but in some instances it is off by 1 less line
that is actually needed.

Perhaps I can add a buffer. Would you be able to point me to the part of the
module where you calculate the number of lines (numLines)? I am thinking if I
add some buffer to the length of the text used in determining numLines then I
would provide enough extra space to avoid cutting off the last lines of text
in the cell.

I tried adding 1 to each calculated numLines value but this would add too
large a buffer and double the length of the report.
 
G

Guest

This is only a preliminary finding, but I made a small change in the code
which seems to solve my problem.

I updated the calculation for the width of the bounding rectangle to take
into consideration the margins of the control. The estimation still tended to
run low occasionally, so I reduced the calculated width to 98%:

..Right = ((ctl.Width - ctl.LeftMargin - ctl.RightMargin) / (TWIPSPERINCH /
lngDPI)) * 0.98
 

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