• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 62
  • Last Modified:

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
0
Ronald Malk
Asked:
Ronald Malk
4 Solutions
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now