Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Developer Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
button to increase fontsize
Harold Laski 
    
4 years ago
I have a field that is to contain Text.  The length of the field has to be limited to 25 characters if it is font size 12 but can be 40 characters if it is font size 9. Can this be automatic on exiting the field or if not can I program 2 buttons next to the field, one with a plus sign and the other with a "-" sign to increase or decrease the character size  within 2 fixed sizes, that being 9 and 14 (readable fonts for our report which is actually a prescription)
Harold Laski OP  @Reply  
    
4 years ago
I hav e solved this partially using the video of Mr. Rost called FONT SIZE by building the two button "+" and "-". Can it be done automatically so that as I enter the information in the field or even, if that is not possible, after I leave the field, then the program will "automatically create the largest size possible within boundaries (font size 9 to font size 14.)
Adam Schwanz  @Reply  
           
4 years ago
I wouldn't change characters based on the font size, I would change font size based on the characters. So if you put in 20 characters it goes to size 12 but if you put in 30 characters it changes to size 9. You could do this with the on load event of the report.

Use String Functions Len to find the length of the text in the field, and then change the font size as needed.

If (Len([Field] <=25)) Then
  FieldName.FontSize=12
Else
  FieldName.FontSize=9
End If
Kevin Yip  @Reply  
     
4 years ago
Hi Harold, you need to use monospace font for this.  Monospace fonts are those where every letter is the same width, such as Consolas, or Courier New.  In all other fonts, a "W" would be much wider than an "i", and you can't tell for certain how many letters will fit.

I did a test with a text box that is 2.3333in wide and uses a monospace font.  It fits:
25 chars at font size 12,
27 at size 11,
29 at size 10,
32 at size 9, and
38 at size 8.

To have font size change "on the fly", you need to use the text box's "Change" event procedure.  It is run whenever the text box's content is changed.  

In the code below, I reduce font size just before the max length is reached.  E.g. even though font size 11 allows 27 chars, I change font size when the user types the 26th char.

My code also assumes font size 8 is the smallest you prefer, and won't do anything if the user types more than 38 chars.


Private Sub MyTextBox_Change()
    Dim n As Integer

    ' The .Text property returns the currently displayed text.
    ' Get length of currently displayed text.
    n = Len(Me!MyTextBox.Text & "")

    ' Set font size based on n.
    ' See Richard's video on the Switch() function.
    Me!MyTextBox.FontSize = Switch(n >= 33, 8, n >= 31, 9, n >= 28, 10, n >= 26, 11, True, 12)
End Sub


This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/6/2026 9:41:45 AM. PLT: 0s