text mask problem

K

Keith G Hicks

A2k.

I'm using the following to mask an unbound text box so that the user can
ONLY enter 50 characters:

CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

I seem to recall this is a problem with access since this also means that
editing in that control means that typing in the middle of the string
overwrites characters regardless of the how the keyboard key "Insert" is set
(on or off).

I need to limit the # of charactes AS the user types. I do NOT want to Trim
the characters afterward, nor do I want to pop up some lame warning in the
BeforeUpdate event or in the ValidationRule property. That's dumb. How can I
limit the number of characters in an UNBOUND control AS the user types
without screwing up the insert behavior? There ought to be a "MaxChars"
property on text boxes.

So here's what I did and it seems to work peachy (and I removed the
"CCCCC..." mask):

Private Sub CertHolderName_KeyPress(KeyAscii As Integer)
If Len(Me.CertHolderName) > 50 Then
KeyAscii = 0#
End If
End Sub

Is that the best solution?

Thanks,

Keith.
 
K

Keith G Hicks

Well I spoke too soon. My solution is not working. How can this be handled?

Keith
 
K

Keith G Hicks

It would appear that in the code:

Private Sub CertHolderName_KeyPress(KeyAscii As Integer)
If Len(Me.CertHolderName) > 50 Then
KeyAscii = 0#
End If
End Sub

the expression

Len(Me.CertHolderName)

always returns 0 because Me.CertHolderName is always NULL. Why is that?
What's the solution?

Keith
 
P

Pieter Wijnen

And how do you think the code behind the property would differ from the Kb?
<g>
It basically expands on your attempt with the len function, only referring
to the text property instead the value property in your code, which is not
updated as you type

Pieter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top