Limiting text in a memo field

  • Thread starter Thread starter Bob Dolmetsch
  • Start date Start date
B

Bob Dolmetsch

I have several forms with memo fields. I want to prevent
users from entering more than they can see on the screen,
but nothing I do has that effect. Even with scroll bars
users can type beyond the limits of the display area.
 
I do this with TextBoxes. Determine the maximum number of
characters you want to allow in the field and then check
it in the Onchange event of the control. Here is the code
I used for a control named txtSvcCode where the user
enters a Service Code which cannot be more than 10
characters long:

Private Sub txtSvcCode_Change()

' if the code entered in 10 or fewer _
' characters then end the sub:
If Len([txtSvcCode]) < 11 Then
Exit Sub
End If

' otherwise trim the entry and _
' display an error message:
Dim strSC as String
strSC = Mid([txtSvcCode],1,10)
[txtSvcCode] = strSC

MsgBox "A Service Code cannot me more than 10 characters
long."

End Sub

Hope this helps!

Howard Brody
 
Back
Top