Excluding unwanted characters when typing...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

For a particular control, I want to keep the user from entering a particular
character ("~") through keystrokes; however, I want to be able to
programatically enter that character in the control later as a means of
controlling uniformity of the data. I suspect one would use the "OnKeyDown"
or "OnKeyPress" event.

How might I programmatically reject that character if typed by the user.
 
David:

Something like this:

Private Sub Text0_KeyPress(KeyAscii As Integer)
If KeyAscii = 126 Then DoCmd.CancelEvent
End Sub

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


For a particular control, I want to keep the user from entering a particular
character ("~") through keystrokes; however, I want to be able to
programatically enter that character in the control later as a means of
controlling uniformity of the data. I suspect one would use the "OnKeyDown"
or "OnKeyPress" event.

How might I programmatically reject that character if typed by the user.
 
Hi David,

This won't stop a user from pasting a ~ into the control. One way of
preventing that might be to use something like this (untested air code)
in the control's BeforeUpdate event:

With Me.ActiveControl
.Text = Replace(.Text, "~", vbNullStr)
End With
 
Back
Top