Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Prevent user enter special character in a form

Posted on 2002-05-27
3
Medium Priority
?
1,721 Views
Last Modified: 2010-08-05
Dear Experts,

I have an table with two text field: [staffcode] & [staffname].
I also have a input form for user to input those data.

My question is how to prevent user entering special character " and ' on the text field.

For example, I don't want user enter [lawrence"chan"] or [law'chan'] on the text field.

Please help
0
Comment
Question by:law99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 10

Expert Comment

by:RichardCorrie
ID: 7037224
use the KeyPress event to cancel the entry thus:

Private sub txtSurname_KeyPress(KeyAscii as integer)
' 39 is single quote, 34 is double quote
if KeyAscii = 39 or KeyAscii = 34 then
   KeyAscii = 0 ' null string
end if
End Sub

Beware though, this could lead to some user confusion as they keep hitting the quote key but nothing is output.

If you set the Form KeyPreview property to True you need only create a Form_KeyPress event.  This will affect all data entry on the form.

Richard
0
 
LVL 6

Accepted Solution

by:
Mach1pro earned 400 total points
ID: 7037273
Set the forms KeyPreview to true
Add the following code to the textboxes KeyUp event

If KeyCode = 222 Then
    If Shift = 1 Then
         MsgBox "Please do not use quotations"
    Else
         MsgBox "Please do not use apostrophes"
    End if
    Me.Activecontrol = Left(Me.ActiveControl.Text, Len(Me.ActiveControl.Text) - 1)
End If
0
 

Author Comment

by:law99
ID: 7037978
Althought both answers are correct, the answer of Mach1pro can give user a warning message when they input apostrophes.

This should be a better answer

Thanks
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question