limit text string length no to exceed the width of a box

Hi All,
It's more likely not possible but I said I give it try.
Any possibility to limit text string length no to exceed the width of a box, other than counting the number of characters,
What I mean is while typing or after update if a part of the text string not showing in the box, a message pops up,
I know I can use the (Len) but I don't prefer to because it doesn't serve my purpose
Ronald MalkAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PatHartmanCommented:
What you see in a box depends on the box size, the font, and the point size and to a certain extent the monitor and the screen resolution.  And then there is the problem of proportional fonts.  An I takes much less room than an M so even counting characters won't help unless you're prepared to figure out the twips each character takes and examine each character to determine what it is and calculate its width.

So, the short answer is you can probably come close.  The long answer is do you have the time and energy to try?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gustav BrockCIOCommented:
There is no built-in tools for this. You may be able to adopt the old code from Stephen Lebans:

TextWidth and TextHeight

TextHeightWidth.zip is a replacement for the Report object's TextWidth and TextHeight methods. It is multiline aware and can work in both Report and Form views. Includes a sample report to show you how to autosize individual controls with different formatting on the same line to simulate RTF style text.

/gustav
0
Anders Ebro (Microsoft MVP)Microsoft DeveloperCommented:
Not impossible to restrict it to the size of the textbox, but I would argue the best approach would be to limit the string length directly in the table. If you have a short text field, with maximum length 5, then access will automatically prevent you from typing more than 5 characters into the bound textbox.  No code required at all.
0
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
You can limit based on an input mask or by using Len() in the OnChange event, but as Ander's pointed out, limiting a field is best done by database design.

 Also, all the issues Pat pointed out need to be taken into account when doing the GUI.  You'd have to use a fixed space font and size the control accordingly to get close.

  Last, as gustav said,  there's probably a programmatic way of doing this, but I not aware of anyone that has bothered.   If you want, we can try and cobble something together for the OnChange event, but I'm not aware of any ready made examples.

Jim.
0
Ronald MalkAuthor Commented:
Thank you all for the replies, it seems to be possible if I spend a big time on it but even though I would later have problem never thought of it the result may differ between different computers monitors as Pat pointed out in his comment, therefore I used the Len function as it's the best possible use in my case.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.