View Full Version : Enabling Msg Box When Char Maximum Has Been Reached


Theman
01-31-2001, 10:15 AM
I want to limit a text field to no more than eighty characters. If a user exceeds that character limit then a message box should be displayed to warn of the limitation and then give the option to the user to either re-enter or cancel and move elsewhere on the form. Any ideas? Thanks.

ntp
01-31-2001, 11:22 AM
Try this code to prevent the user from entering anything beyond 80 characters

Private Sub Text0_Change()
If Len(Me.Text8.text) > 80 Then
if (MsgBox ("OK to re-enter",vbOkCancel) = vbOk) then
Me.Text8.text = Left(me.text8.text,80)
me.text8.setstart = 80
else
me.text8 = ""
me.othercontrol.setfocus
end if
End If
End Sub

if the user decides to reenter, leave the 80 characters otherwise remove them then move focus to another control.

ntp

Theman
01-31-2001, 12:24 PM
It worked great! Thanks.