Solved Can the font size be reduced to fit column width? (1 Viewer)

yunhsuan

Member
Local time
Today, 23:46
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!
 

Gasman

Enthusiastic Amateur
Local time
Today, 16:46
Joined
Sep 21, 2011
Messages
14,263
Let the textbox grow?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 16:46
Joined
Feb 19, 2013
Messages
16,607
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
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 10:46
Joined
Feb 28, 2001
Messages
27,171
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.)
 

yunhsuan

Member
Local time
Today, 23:46
Joined
Sep 10, 2021
Messages
54
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?
 

yunhsuan

Member
Local time
Today, 23:46
Joined
Sep 10, 2021
Messages
54

CJ_London

Super Moderator
Staff member
Local time
Today, 16:46
Joined
Feb 19, 2013
Messages
16,607
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 Hartman

Super Moderator
Staff member
Local time
Today, 11:46
Joined
Feb 19, 2002
Messages
43,257
In a continuous form, you are seeing multiple records but there is only ONE set of properties and those properties apply to ALL visible instances of the form. Conditional formatting was introduced to get around this problem but I don't think point size is changeable this way.

If you use a DS view form, the user can expand the height of the rows the same way he does in Excel by draging the bottom down. However, this enlarges ALL visible rows, not just the one that was dragged. The user can then drag the line back up when he is finished.

The way I generally recommend to the users is to use the shift - F2 to open a zoom box. This box is data aware and so if they update in the box, the update is transferred to the form when the box closes.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 16:46
Joined
Feb 19, 2013
Messages
16,607
Pat - this is a report, not a form. And as you say, conditional formatting does not apply to font size.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 11:46
Joined
Feb 19, 2002
Messages
43,257
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.
 

yunhsuan

Member
Local time
Today, 23:46
Joined
Sep 10, 2021
Messages
54
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?
 

yunhsuan

Member
Local time
Today, 23:46
Joined
Sep 10, 2021
Messages
54
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?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:46
Joined
May 7, 2009
Messages
19,230
set all Textbox Cangrow to Yes.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 11:46
Joined
Feb 19, 2002
Messages
43,257
It only looks weird if you have boxes around the controls. If you want to have all the boxes grow, try using the layout option. Personally, I never use this because its other properties are so annoying but It might solve your problem.
 

Users who are viewing this thread

Top Bottom