restrict user input to 2 lines

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

Hi

Using Access 2002 I have a text box on a form in which I want to be able to
restrict the user to use only 2 lines of text.

Whilst I can make the box height to only show 2 lines of text to some users
they input more lines.

What is the best way to achieve this

TIA

Tom
 
the easiest way might be to simply set the FieldSize property of the field
in the underlying table to allow only x character/spaces to be entered in
the field.

hth
 
In you table, make the datatype is text, not memo. Text can be limited to
specific number of characters.
 
Hi Tina & Anne

Had already explored that route - what you suggest will limit the number of
characters but not the number of lines those characters are on. I need to be
able to restrict the number of lines to 2 only

Tom
 
hi Tom,
Using Access 2002 I have a text box on a form in which I want to be able to
restrict the user to use only 2 lines of text.

Whilst I can make the box height to only show 2 lines of text to some users
they input more lines.

What is the best way to achieve this
Normally each line is terminated by a vbCrLf:

Dim Position1 As Long
Dim Position2 As Long

Position1 = InStr(1, YourField.Value, vbCrLf)
If Position1 > 0 Then
Position2 = InStr(Position1, YourField.Value, vbCrLf)
If Position2 > 0 Then
YourField.Value = Left(YourField.Value, Position2 - 1
End If
End If


mfG
--> stefan <--
 
Hi Stefan

Thanks for your input but on trying your code of:

Dim Position1 As Long
Dim Position2 As Long

Position1 = InStr(1, YourField.Value, vbCrLf)
If Position1 > 0 Then
Position2 = InStr(Position1, YourField.Value, vbCrLf)
If Position2 > 0 Then
YourField.Value = Left(YourField.Value, Position2 - 1) ' closing
bracket omitted in your example
End If
End If

What happens is that if 2 or more lines of text are entered all but the 1st
line are deleted whereas I would like that the 1st 2 lines are kept.

How can that be overcome

TIA

Tom
 
hi Tom,
Position1 = InStr(1, YourField.Value, vbCrLf)
If Position1 > 0 Then
Position2 = InStr(Position1, YourField.Value, vbCrLf)
Typo, must be:
Position2 = InStr(Position1 + 1, YourField.Value, vbCrLf)
What happens is that if 2 or more lines of text are entered all but the 1st
line are deleted whereas I would like that the 1st 2 lines are kept.


mfG
--> stefan <--
 
Back
Top