Limiting Inputs

RichB

New member
Local time
Today, 08:18
Joined
May 15, 2001
Messages
96
Is there a way, code or other to limit the user to only the number of characters in a field. Here's what I mean. I have a text field that I have limited to 200 characters. When you fill out the form it lets you just keep typing past the 200. Can you stop there input once it reaches 200?

Thanks
RichB:confused:
 
Thanks, but it didn't work. I changed the number in the code to 200 like I need but it goes to debug on the second "If" line. I put this in the KeyPress() event of the textbox.

The code goes:

If KeyAscii = 200 Then KeyAscii = 0
If Len(Me.txtGenInfo.Text) = CInt(Me.txtGenInfo.Tag) Then
If KeyAscii >200 Then KeyAscii = 0
End If

I assume this would stop the input at the 200th character.

RichB
 
RichB said:
Thanks, but it didn't work. I changed the number in the code to 200 like I need but it goes to debug on the second "If" line. I put this in the KeyPress() event of the textbox.

The code goes:

If KeyAscii = 200 Then KeyAscii = 0
If Len(Me.txtGenInfo.Text) = CInt(Me.txtGenInfo.Tag) Then
If KeyAscii >200 Then KeyAscii = 0
End If

I assume this would stop the input at the 200th character.

RichB
NO!
Put the number you want to limit the textbox to in the textbox's Tag property.
 
Hi,
A friend did this for me and it works. Try it out for your case

Code:
Private Sub REP_TAG_KeyPress(KeyAscii As Integer)
    If Len(Me.REP_TAG.Text) >= 6 Then
        If KeyAscii > 48 And KeyAscii < 122 Then
            KeyAscii = 0
        End If
        Me.REP_TAG.SelStart = 7
    End If
End Sub

You can add your own custom message to it alerting the input user why he can't insert anymore characters.

Regards,
Ode
 

Users who are viewing this thread

Back
Top Bottom