Limit number of lines in a memo field

J

Jeff

Does anyone know if it is possible to limit the amount of lines that can be
entered into a memo field?

I need to be able to restrict the user to 20 lines so that the text will fit
in a box on pre printed stationery.

I can obviously removed the scroll bar from the form but that doesn't stop
them typing!

Any ideas anyone?
 
D

Douglas J. Steele

Assuming it's a bound field, you can check the length of what they've typed
in the BeforeUpdate event of the control, and pop up a message if it's too
long:

Private Sub Text1_BeforeUpdate(Cancel As Integer)

If Len(Me.Text1 & vbNullString) > 600 Then
MsgBox "You've typed too much."
Cancel = True
End If

End Sub

(The 600 is a guess: you'll have to play with it...)
 
M

Maurice

Looks to me like this is going to be tough. What is a line? How will you be
counting these lines. Will the criteria be a period at the end of a sentence
or are you looking for carriage returns here. I think you are better off
testing the lines for yourself. Create a test situation where you fill the
memo field with 20 lines and then count the characters used. You can test on
number of chraracters with the Len function which you can place in a event of
the control.
 
J

John Spencer

Not sure this is the answer to your problem, but I would check out the
following URL. If this solution does not work for you, check around on
Stephen Lebans' site - there may be something else there you can use.

http://www.lebans.com/limittextinput.htm

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 

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