Solved Can the font size be reduced to fit column width?

yunhsuan

Member
Local time
Tomorrow, 03:34
Joined
Sep 10, 2021
Messages
54
Hello~
I create a report. Sometimes, the the length of text in cell is too long to fit column width.
In Excel, the font size can be reduced to fit column width automatically. Can this also work in Access?
Can any one tell me how to do or give me some example?
Thanks!
 
you can reduce the font size if you want - use the detail (or whatever section it is in) on format event to change the font size - but much easier to set the control cangrow property to true. If this is not an option then use code similar to that used in Excel - something like

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

    If Len(myControlName) > 15 Then myControlName.FontSize = 8
    
End Sub
 
To answer the question another way - there is no automatic font size adjustment to shrink the text. Access uses the other method of making room - by letting the textbox get taller (if you use the "CanGrow" property.)
 
 
you can reduce the font size if you want - use the detail (or whatever section it is in) on format event to change the font size - but much easier to set the control cangrow property to true. If this is not an option then use code similar to that used in Excel - something like

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

    If Len(myControlName) > 15 Then myControlName.FontSize = 8
   
End Sub
I have tried this, but it changed font size of all text in the whole column. Can I change the cell that text length exceeds column width only?
 
I got error in this line, but I don't know why?
Code:
 Do Until TextWidth(strText) < ctl.Width '- (ctl.Width * 0.26)
I use the Chinese edition. Is it possible due to this?
 
I have tried this, but it changed font size of all text in the whole column.

you need to 'reset it' to the original font size try

If Len(myControlName) > 15 Then myControlName.FontSize = 8 else myControlName.FontSize =11
 
Pat - this is a report, not a form. And as you say, conditional formatting does not apply to font size.
 
To answer the question another way - there is no automatic font size adjustment to shrink the text. Access uses the other method of making room - by letting the textbox get taller (if you use the "CanGrow" property.)
When I use the "CanGrow" property, only the height of cell with more characters becomes higher. But, the height of other cells in the same row remains unchanged. That is, cells with different heights exist in the same row. It become weird when the grid is shown in report.
Is there a way to solve this problem?
 
On a report, the problem is easy to solve. Set the can grow/can shrink properties of the control AND the section that holds it to Yes. The text box will become as long as needed to show the entire text.
When I use the "CanGrow" property, only the height of cell with more characters becomes higher. But, the height of other cells in the same row remains unchanged. That is, cells with different heights exist in the same row. It become weird when the grid is shown in report.
Is there a way to solve this problem?
 
set all Textbox Cangrow to Yes.
 

Users who are viewing this thread

Back
Top Bottom