Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2004

    Unhappy 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!).

    MS Support Page

    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).

  2. #2
    Join Date
    Mar 2004
    San Diego
    You can apply an input mask to the text box. Look in the Properties under Input Mask. You can create your own if you click on the "Edit List" button within the window that pops up.

  3. #3
    Join Date
    Feb 2004
    I'm very much a novice at this so if I'm completely wrong please don't shoot me

    Can you not put something like the following code on your exit button or the like

    Private Sub Exit_Click()
    On Error GoTo Err_Exit_Click
    'Check the length of the input field and advise user if over length

    If (Len(YourField) > 8) Then
    MsgBox "The text you have entered is too long, please amend", vbOKOnly

    End If

    Exit Sub

    MsgBox Err.Description
    Resume Exit_Exit_Click


  4. #4
    Join Date
    Jun 2004
    Guys (and gals where applicable),

    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 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

    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!).

    Have you got any ideas?

  5. #5
    Join Date
    Apr 2004
    Sydney Australia
    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 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?

    Last edited by Mike375; 06-05-04 at 06:44.

  6. #6
    Join Date
    Jun 2004
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts