SetUp Maximum Length

mr moe

Registered User.
Local time
Today, 03:50
Joined
Jul 24, 2003
Messages
332
Hello All,

How can I setup a field length for an unbound textbox. I know maybe it's easy thing to do, but I can't figure it out. Thanks.
 
You could use the inputmask property
 
In the KeyPress() event of the textbox:

Code:
    Static strValue As String
    If Len(strValue) = CInt(Me.txtTitle.Tag) Then
        KeyAscii = 0
        Exit Sub
    End If
    strValue = strValue & Chr(KeyAscii)

Put the number you want to limit the textbox to in the textbox's Tag property.
 
Thanks Guys,
I used the inputmask. It worked fine.
 
Mile-O-Phile,
I used your method instead because it's a password field that I'm working on, the only thing is that when I enter the value I can't back space it or edit it unless I close the form and open it again, any suggestions. Thanks.
 
My fault for being hasty at times:

Change the code to this:

Code:
    If KeyAscii = 32 Then KeyAscii = 0
    If Len(Me.MyText.Text) = CInt(Me.MyText.Tag) Then
        If KeyAscii <> 8 Then KeyAscii = 0
    End If


And set your textbox's InputMask property to Password.
 
Thanks man, you're so smart honestly. I appreciate it.
 
Mile-O-Phile,
Sorry if I'm bothering you, but there is one bug with the code, the first time you enter a number, you get an error message, this happens on the first key press, then if i click end on the error message window it will work again.
 
What's the error? I can't generate one.

The only time I can is if I don't put a value in the textbox's Tag property.
 
The error is : Runt-time error '2196'
Thanks,

That's when I try to put a value the first time, when i click on end the error and then I try again it works. Maybe I need to put an error trap????
 
Thanks, It worked I just put on error statment.
 
What's the error description for '2196'?
 

Users who are viewing this thread

Back
Top Bottom