Restricting character range

J

John

Hi

I need to restrict user's input to safe characters range i.e. first 128
ASCII characters. What is the way to filter the input when a) user is typing
in a text field and b) user pastes text into a field?

Many Thanks

Regards
 
K

Ken Sheridan

To prevent typing in a high ASCII character put the following in the
control's KeyPress event procedure:

If KeyAscii > 128 Then KeyAscii = 0

To remove any high ASCII characters from a string pasted in put the
following in the control's AfterUpdate event procedure:

Dim n As Integer
Dim strChr As String, strText As String
Dim ctrl As Control

Set ctrl = Me.ActiveControl

With ctrl
For n = 1 To Len(.Value)
strChr = Mid(.Value, n, 1)
If Asc(strChr) <= 128 Then
strText = strText & strChr
End If
Next n
.Value = strText
End With

Ken Sheridan
Stafford, England
 

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