limiting text in form

  • Thread starter Thread starter don
  • Start date Start date
D

don

I am trying to limit the number of characters one can
enter into an UNBOUND textbox other than using the input
mask.

The following code is not working but not sure why:

Private Sub GabId_Change()
On Error GoTo ErrorHandler
Dim lFieldLength
lFieldLength = 9
if len(me.[GabId])> lFieldLength then
Me.[GabId] = Left(Me.[GabId], lFieldLength)
End If

Exit Sub
ErrorHandler:
MsgBox Err.Number & vbCrLf & vbCrLf & Err.Description

End Sub


Thanks in advance

don
 
I am trying to limit the number of characters one can
enter into an UNBOUND textbox other than using the input
mask.

The following code is not working but not sure why:

Private Sub GabId_Change()
On Error GoTo ErrorHandler
Dim lFieldLength
lFieldLength = 9
if len(me.[GabId])> lFieldLength then
Me.[GabId] = Left(Me.[GabId], lFieldLength)
End If

Exit Sub
ErrorHandler:
MsgBox Err.Number & vbCrLf & vbCrLf & Err.Description

End Sub

Thanks in advance

don
What is this len(me.[GabId])>lFieldLength ?

Do you wish to retain the first 9 characters?
Or the first 8 characters?
The Change event fires as each character is entered.
If you wish to stop entry at the 9th character you must allow the 10th
character to be typed, then roll it back 1 character.
To retain 8 characters allow the 9th entry and roll it back to 8.
And, until the data has been saved, you must refer to the control's
..Text property, not it's default .Value property.

Private Sub GabId_Change()
On Error GoTo ErrHandler

If Len(Me![GabID].Text) = 10 Then
MsgBox "You cannot enter any more characters"
Me![GabID].Text = Left(Me![GabID].Text,9)
End If

Exit_This_Sub:
Exit Sub
ErrorHandler:
MsgBox Err.Number & vbCrLf & vbCrLf & Err.Description
Resume Exit_This_Sub

End Sub
 
Back
Top