'font size to fit' textbox

  • Thread starter Thread starter Dale Walker
  • Start date Start date
D

Dale Walker

Anyone know how to dynamically reduce the font size of text within a
textbox so that all text within a field will always be printed on one
line?

I'm not talking about text wrapping or (CanGrow/CanShrink) type
functions.
 
http://www.lebans.com/autosizefont.htm
AutoSizeFont.zip is a database containing a function to automatically
resize a Control's Font to fit the current record's contents. Works in
the Form's Current and/or Change events.

Version 2: Updated to use the new ,more accurate, fTextHeight function.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
http://www.lebans.com/autosizefont.htm
AutoSizeFont.zip is a database containing a function to automatically
resize a Control's Font to fit the current record's contents. Works in
the Form's Current and/or Change events.

Version 2: Updated to use the new ,more accurate, fTextHeight function.

Works great in Forms but how do I get it to work in Reports?
 
The code in the sample Form must be copied to your Report.

Form Load event -> Report Open event
Form Current event -> Relevant Report Section Format event(Detail in
most cases)


--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
The code in the sample Form must be copied to your Report.

Form Load event -> Report Open event
Form Current event -> Relevant Report Section Format event(Detail in
most cases)

Sorry, still not working. Code barfs at the me.repaint line (compile
error: method or data member not found).

Doesn't .repaint only apply to forms?
 
The Repaint method is only for Forms - just comment it out.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
The Repaint method is only for Forms - just comment it out.

Tried that, no errors but no size change either.

One thing that might conceivably be a problem is that I'm using
Japanese characters instead of ASCII.

Also using Access 2003.
 
You said the sample Form worked on your system so you should be able to
get the Report working as well.

I just saved the Sample Form as a Report.

Copied the Form's Load event to the Report's Open event.
Copied the Form's Current event to the Report Detail Section's Format
event and everything worked fine.

Here is the code behind my Report.


Option Compare Database
Option Explicit



Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim lngTextHeight As Long

With Me.txtExtraInfo
' Copy the original Font height from the Tag property
.fontsize = .Tag
Do While .fontsize > 2
lngTextHeight = fTextHeight(Me.txtExtraInfo)

' Does text fit? If yes then exit
If lngTextHeight < .Height Then Exit Do

' Decrease font height
.fontsize = .fontsize - 1
Loop
End With
End Sub

Private Sub Report_Open(Cancel As Integer)
' Copy the TextBox default Fontsize to its Tag property.
Me.txtExtraInfo.Tag = Me.txtExtraInfo.fontsize
End Sub

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
You said the sample Form worked on your system so you should be able to
get the Report working as well.

I think I've spotted the problem. It occurs in both form and report
versions.

To make Japanese 'vertical' text, I was making the width of the
textbox just one character wide, so that the sentence would wrap down.

I've got a feeling Access (or the code) can't work out the correct
width of doublebyte characters and therefore miscalculates the number
of lines needed to fit in the height of the textbox. If I add a
newline between characters (or before any wrapping takes place for
wider examples), it works fine.

I'll have a go at rejigging the code but I'm that hot on VB
(especially when jiggling with twips and wotnot)

Also, I don't suppose you have a horizontal font scaler knocking
around anywhere (one that'll stick the whole field on one line)?

That'll come in handy for the next little projectette I have.
 
Back
Top