Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Limit Unbound Text Box Length

Status
Not open for further replies.

nag9127

Technical User
Mar 15, 2007
76
US
I have an unbound text box that, upon form processing, will be inserted into a table field. I want to limit the number of characters that the text box will allow to 80. How can I do this? Thanks for any help!!
 
In the BeforeUpdate event procedure of the text box:
If Len(Me![text box] & "") > 80 Then
MsgBox "Text too wide"
Cancel = True
End If

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Far be it from me to suggest an alternative to PHV's perspicacious suggestion, but here goes. If you want to just truncate automatically, perhaps this in the AfterUpdate event:
Code:
If Len(Me![blue]MyField[/blue] & "") > 80 Then
    MsgBox "Too much text!  Truncating to 80 characters..."
    Me![blue]MyField[/blue] = Left(Me![blue]MyField[/blue], 80)
End If
HTH,

Ken S.
 
Alternative solution(will prevent user from entering more than 80 characters without letting him make the useless effort to type the extra text...)
Input mask of the textbox: CCCCCCCCCC (80 times the letter C)

HTH


[pipe]
Daniel Vlas
Systems Consultant

 
How are ya nag9127 . . .

If the user is initially typing data in the unbound textbox, for an [blue]on the fly limit of 80[/blue], copy/paste the following to the [blue]On Key Down[/blue] event of the unbound textbox:
Code:
[blue]   If Len(Me![purple][b][i]TextboxName[/i][/b][/purple].Text) = 8 Then
      If (KeyCode > 47 And KeyCode < 58) Or _
         (KeyCode > 64 And KeyCode < 91) Or _
         (KeyCode > 185 And KeyCode < 193) Or _
         (KeyCode > 218 And KeyCode < 220) Then
         KeyCode = 0
      End If
   End If[/blue]

Calvin.gif
See Ya! . . . . . .
 
For another option, in the Validation Rule property of the text box put:

Len([txtBoxName]) <= 80

and in the Validation Text property put whatever text you want displayed to the user if the text entered exceeds 80 characters.

TMTOWDI - it's not just for Perl any more
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top