shrink to fit

sparx

Morphed Human
Local time
Today, 09:51
Joined
Jul 22, 2002
Messages
80
I know the property exists in Excel, but can I shrink the font of a control depending on the size of the text, while keeping the control the same size??

TIA,

Sparx
 
Well "No" is the short answer, a? is even shorter but we won't go into that now. I did see a post somewhere some time ago about how to do it in code, but I didn't keep a copy... I'll have a look just in case... But any way, if I recall correctly, the idea was you counted the # (I'm doing American again) of characters, and at particular numbers the code changed the text size. I think it only works well with a regular spaced text like courier.
 
sparx,

Experiment with this:

Code:
If Len(Me.MyControl) > 10 Then
   Me.MyControl.Fontsize = 10
If Len(Me.MyControl) > 15 Then
   Me.MyControl.Fontsize = 8
If Len(Me.MyControl) > 20 Then
   Me.MyControl.Fontsize = 6
End If

Wayne
 
raskew said:
Stephen Lebans is the reigning master of this type of solution. Try here:
http://www.lebans.com/autosizefont.htm
raskew,

Wonderfull!! THANK YOU!! Exactly what I am looking for!!
:D

Needed a way to automatically calculate (adjust) width / height of textbox (or other controls).

Searching saved me time from explainging what I wanted and having someone re-answer the same question!

Edit: Reason for all the words in my sentence above is to help other people searching. I decided adding keywords would help, so here goes;

Keywords: Automatic, Calculate, Adjust, Control, Textbox, Memo, Combobox, Label, Width, Height, Size, Font


Edit #2: Go to this thread to vote on whether or not adding a keywords section is a good idea or a bad one.
http://www.access-programmers.co.uk/forums/showthread.php?s=&threadid=59948
 
Last edited:
Hi there, I am just a beginner.

Does anyone know if it is possible to adapt this code for REPORTS?

The code doesn't seem to be working as I think it it specific to FORMS?
 
Yes; report is same as snapshot of the record; it cannot be "edited" in the report. You can define how it must be formatted when opening it, but after the fact, it's as is.
 
This will work for Reports.:


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

Dim Ctrl As Control

If Len(Me.Text4) >= 12 Then
Me.Text4.FontSize = 7
Else
Me.Text4.FontSize = 8
End If

End Sub
 
I know the property exists in Excel, but can I shrink the font of a control depending on the size of the text, while keeping the control the same size??

TIA,

Sparx
Hi these codes can help you. copy it in details properties and on print event or use the attached file:
Code:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)Dim ctl As Control, strText As Variant, strName As String' This routine uses the TextWidth methods to determine the maximum size' of font possible to ensure a text string is printed in full in the' report's current font without loosing any characters.        Me.ScaleMode = 1 ' set all measurments to twips        For Each ctl In Me.Detail.Controls           If ctl.ControlType = acTextBox Then                strName = ctl.Name                    If Nz(ctl.Tag, "") = "" Then                ctl.Tag = ctl.FontSize            End If                                    ' set the control's fontsize to a suitable large size to begin with            ctl.FontSize = ctl.Tag        ' make sure the report font size is equal to the control's fontsize.            Me.FontSize = ctl.FontSize                ' grab the text from the control            strText = ctl.Value                ' evaluate the Loop until the text fits the Width of the box less 24%. Do this        ' by reducing the font size incrementally and re-testing the Loop's criteria.           If Len(strText) > 0 Then            Do Until TextWidth(strText) < ctl.Width '- (ctl.Width * 0.26)                ctl.FontSize = ctl.FontSize - 1                ' reset the report's font size so the TextWidth function will                ' continue to track the reducing font size correctly.                Me.FontSize = ctl.FontSize            Loop                    ' now evaluate for the height of the text to make sure it fits vertically            Do Until TextHeight(strText) < ctl.Height - (ctl.Height * 0.26)                ctl.FontSize = ctl.FontSize - 1                ' reset the report's font size so the TextHeight function will                ' continue to track the reducing font size correctly.                Me.FontSize = ctl.FontSize            Loop                End If        End If            Next ctlEnd Sub
 

Attachments

Last edited:

Users who are viewing this thread

Back
Top Bottom