Limiting text in a memo field

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

Howard Brody

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top