shrink text box

basilyos

Registered User.
Local time
Today, 04:54
Joined
Jan 13, 2014
Messages
256
hello,


any idea how can i shrink textbox in form when the text is long?


in report the can shrink and can grow work perfect but not in form
 
Perhaps you could set the Width property of the text box in the forms OnCurrent event and/or in the AfterUpdate event of the text box
 
The real problem is that for reasons unknown, Access doesn't have a way to tell you how big your text string will be when displayed. There IS a subroutine to do this for printed reports, but it doesn't work for displayed items. Therefore you cannot easily know exactly how big the text will be unless you use a non-proportional font like Courier New (which has a fixed width).

At least in theory, a Courier New character on-screen with a font size = 72 points occupies one inch by 3/4 inch. That height is also 1440 twips because Access forms and reports use twips as a size measurement, 1440 per inch. So 20 twips per point. Somewhere in there is enough info so that you can compute the size of your string for non-proportional font Courier New simply by knowing the number of bytes in the string, i.e. the LEN() function.

I don't know the nominal sizes of other fonts. You would have to measure any other fonts you wanted to use AND if you used a proportional font, then the length required would be less than your computed size due to non-uniform character sizes. Also, if you have an option to turn off kerning, that would affect string length.

Kerning is the practice of "squishing" letters together if there is some room, like for example consider "Te" as the beginning of a word. The little e can be moved closer to the capital T because the e fits under the T. Lots of letters have the ability. Capital F also can have some kerning. So if the font allows kerning, you will compute too great a width.

As to WHEN you do this, I concur with bob fitz that OnCurrent & AfterUpdate are good, but if there is any interdependence between text boxes (i.e. make a change to control X and the contents of the text box change), other events such as OnChange or LostFocus might also be involved.
 
Don't know if this is useful for your case, roughly figured out for Calibri the size as the user wanted to have a specific number of chars display in a text box, so used the formula below to size it. Could probably change the character count to a variable based on len as mentioned in an earlier post:

Code:
    Const TWIPSTOINCHES = 1440
    'TWIPS times (number of inches for 1 character at 8 point Calibri)
    Const TWIPSTOCHARWIDTH = TWIPSTOINCHES * 0.06
    Me.txtWebSite.ColumnWidth = TWIPSTOCHARWIDTH * 20 'desired character width of 20 characters
 
I've converted the utility from Stephen Lebans website to ACCDB so you should be able to try it out. I've not tried it myself

Personally I don't like reducing size text when its too long to fit as I think it can look untidy.
Instead I recommend using one of the following to display all the lengthy text when you click on the textbox
a) the built in Access Zoom control (click Shift+F2)
b) a small popup form designed for the purpose

attachment.php
 

Attachments

I converted it.
don't know if this will work on continuous form.
 

Attachments

i already made it x64 ready.
 

Users who are viewing this thread

Back
Top Bottom