Unanswered: Limiting the character length of an unbound text box
I've come across a problem and can find no resource for this type of issue. Basically, I'm trying to limit the number of characters allowed within a text field (that's unbound).
In normal terms, a bound text box adopts the 'linked' field's structure when it comes to validating field entry contraints. However, I have fields on a form that I need limitations set on their lengths, which are not bound.
I've scanned the MS website and all I can come up with is the below link which only sorts half of the problem (typical!).
This solution is fine apart from the fact that it's a rather long-winded way of doing this, and the fact that it doesn't take in to account the embedded Paste function (if paste is used, then the keypress event is not triggered).
thankyou greatly for your recent replies, but I've got a couple of probs...
LaurelLee, if I can't suss this then I'm gonna have to resort to the input mask but it becomes a problem for two reasons - firstly, some of the fields I'm using will be limited to 100 chars (me typing '?' x 100 times for each field - very tiring.lol). Secondly, the input field constraints auto-populate a ton of spaces (' ') in the field for the number of chars limited - when a field with an input mask is clicked the cursor stays at that point, as opposed to 'flicking' back to the end of the text contained.
Sticker, The only problem I foresee with that is if several fields are above their limits, then the user will receive error messages for each field failing. I think this would annoy certain less controlled users.lol
The trouble is that this application will go out to a client so it needs to be spot-on where functionality is concerned. The only real methodology I can see is to maintain the same constraint used for a bound text box, but I have no idea of how to duplicate this functionality (even in VBA. In VB it's [control.length = nLength] - simple, but not so in VBA!).
Why not have extra fields in your table and set the charcter limit and then use these for entering the writing.....but the do the following
1) Overlay your unbound text box over the field from the table.
2) When you click on the unbound text box to type then a macro (I am one of those crude macro people so you can express it in code ) with a SetValue action runs which either makes the unbound text box invisible or changes it dimensions...in other words it effectively dissappear.
3) The person now types into the field and is limited by the field setting.
4) A macro is placed on the bound field of the table to run on Lost Focus. This macro is a SetValue action and sets the value of the unbound textbox to be the same as the field. It then sets the value of the table field to Null and it also brings the unbound text box into view by rechanging the dimensions and/or postion or visible/invisible.
You would aslo need to do something if the person clicked back on the text box because then they would not see anything as the underlying field would be empty. Some more thought and some IIF and another text box?
Mike, thanks for you post - much appreciated, but it seems an extremely long winded way of managing a simple field character limit setting.
I have around 15 forms, with approximately 25 fields on each, so it would be implementing a hell of a lot of code, and objects just to achieve a limit on a text field.
Can anyone confirm / deny that there is a function (within Microsoft VBA) to manage this or am I on a wild goose chase. If this is the case, why is it that VBA doesn't include this functionality yet VB does?!
Are there any API's that manage the same functionality?