Manage Learn to apply best practices and optimize your operations.

Limiting entry length in a textbox

This tip describes how to limit the ammount of characters that may be entered into a field.

This only works in R5/Win32 environments. Fields must have the property "Native OS Style" selected.

These scripts use Win32 API calls to change the window class attributes of the selected field and limit the number of characters the user can enter. The following example limits entries in a specific field to 25 characters.

If the user continues to type after 25 characters have been entered, he or she will hear an error beep. If the user tries to paste in text longer than 25 characters, he or she will be unable to do so.

Code in one field does NOT affect other fields on the form unless they also contain the "Entering" code. Different fields can have different limits.

[Form Globals]
Option Public
Declare Function GetFocus Lib "user32" () As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (Byval hWnd As Long, Byval wMSg As Long, Byval wParam As Long, lParam As Long) As Long

Sub LimitText (wHandle As Long, MaxChars As Integer)
 Dim Result As Long
 If MaxChars > 0 Then
  Result = SendMessage(wHandle, EM_LIMITTEXT, MaxChars, 0)
 End If
End Sub

[Field Entering event]
Sub Entering(Source As Field)
 Dim hWnd As Long
 Call LimitText(hWnd, 25)  ' Limits user to 25 chars max in this field
End Sub

Dig Deeper on Lotus Notes Domino Administration Tools

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...