如何禁止文本框中的撇号(输入掩码?) [英] how to forbid an apostrophe in text box (input mask?)

查看:102
本文介绍了如何禁止文本框中的撇号(输入掩码?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了防止未来的撇号错误和错误,

禁止撇号进入文本字段是不是更简单?例如,

不能爱丽丝的餐厅改为Alices Restaurant

在数据输入过程中自动和编程?当我将字符串基于

查询时,这将消除我的连续字符串产生错误。认为这是Dreaded Apostrophe Bug的一个例子。如果我输入一个双撇号,我仍然会在StrSQL中得到错误。另外,它是
在字段中显示为双撇号,比丢失的

撇号更难。


这是一本简单的电话簿。想法?我应该发布代码吗?


谢谢。

Rich Hollenbeck

To prevent future apostrophe bugs and errors, isn''t it just simpler to
forbid an apostrophe from being entered into a text field? For example,
couldn''t "Alice''s Restaurant" be changed to "Alices Restaurant" etc.
automatically and programmatically during data entry? This would eliminate
my concatinated strings from producing errors when I base the string on a
query. Think this is an example of the "Dreaded Apostrophe Bug." If I
enter a double apostrophe I still get the error in the StrSQL. Also, it
appears in the field as a double apostrophe which is uglier than a missing
apostrophe.

This is for a simple phone book. Ideas? Should I post the code?

Thanks.
Rich Hollenbeck

推荐答案

如果你将每个表单的'KeyPreview

设置为是,并且在表格测试的KeyPress事件中,如果KeyAscii为39,并且如果

所以将它设置为零。


这可能限制了应用程序范围,但是:

O'Brians不会很高兴。

很难接受用户的评论。


更好的想法是总是使用双引号你的分隔符。如果它们是嵌入的,你只需要将它们加倍,以便VBA知道它不是字符串的结尾,例如:

"这有一个word""在引号中。

如果你想阻止双引号字符,你可以用它来逃避

。它很少用于数据,除了简单的英寸。


以下代码用单引号替换双引号作为用户

类型。它还用反斜杠替换管道字符,因为它也会导致问题。要使用代码:

1.将其粘贴到通用模块(数据库窗口的模块选项卡)中。

2.将表单的KeyPreview设置为是。 br />
3.将表格的'On Key Press属性设置为:

[事件程序]

4.单击Build按钮(.. 。) 除此之外。 Access打开代码窗口。

在Private Sub ...之间。和结束子行,输入:

调用NoDblQuote(KeyAscii)

Sub NoDblQuote(KeyAscii As Integer)

Select Case KeyAscii

案例34

KeyAscii = 39

案例124

KeyAscii = 92

结束选择

End Sub


-

Allen Browne - 微软MVP。西澳大利亚州珀斯。

访问用户提示 - http:// allenbrowne.com/tips.html

回复群组,而不是mvps dot org的allenbrowne。


" Richard Hollenbeck" < RI **************** @ verizon.net>在消息中写道

news:PiA8d.6520
You can destroy the apostrophy keystroke if you set each form''s KeyPreview
to Yes, and in the KeyPress event of the form test if KeyAscii is 39, and if
so set it to zero.

That''s probably too restrictive to apply application wide, though:
The O''Brians won''t be happy.
It''s difficult to accept users'' comments.

A better idea is to always use double-quotes for your delimiters. You just
have to double them up if they are embedded so that VBA knows it''s not the
end of the string, e.g.:
"This has a ""word"" in quotes."
If you want to block the double-quote character, you can probably get away
with that. It''s rarely used in data, other than as a simple for inches.

The following code replaces the double-quote with a single quote as the user
types. It also replaces the pipe character with a backslash, as it also
causes problems. To use the code:
1. Paste it into a general module (Modules tab of Database window).
2. Set your form''s KeyPreview to yes.
3. Set your form''s On Key Press property to:
[Event Procedure]
4. Click the Build button (...) beside this. Access opens the code window.
Between the "Private Sub..." and "End Sub" lines, enter:
Call NoDblQuote(KeyAscii)
Sub NoDblQuote(KeyAscii As Integer)
Select Case KeyAscii
Case 34
KeyAscii = 39
Case 124
KeyAscii = 92
End Select
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Richard Hollenbeck" <ri****************@verizon.net> wrote in message
news:PiA8d.6520


r3.3117@trnddc05 ...
r3.3117@trnddc05...
为了防止将来出现撇号和错误
禁止撇号进入文本字段是不是更简单?例如,
不能爱丽丝的餐厅。改为Alices Restaurant
在数据输入期间自动和以编程方式?当我将字符串基于
查询时,这将消除我的连接字符串产生错误。认为这是Dreaded Apostrophe Bug的一个例子。如果我输入双撇号,我仍然会在StrSQL中得到错误。此外,它作为一个双撇号出现在现场,这比一个缺少的撇号更丑。

这是一个简单的电话簿。想法?我应该发布代码吗?

谢谢。
Rich Hollenbeck
To prevent future apostrophe bugs and errors, isn''t it just simpler to
forbid an apostrophe from being entered into a text field? For example,
couldn''t "Alice''s Restaurant" be changed to "Alices Restaurant" etc.
automatically and programmatically during data entry? This would
eliminate
my concatinated strings from producing errors when I base the string on a
query. Think this is an example of the "Dreaded Apostrophe Bug." If I
enter a double apostrophe I still get the error in the StrSQL. Also, it
appears in the field as a double apostrophe which is uglier than a missing
apostrophe.

This is for a simple phone book. Ideas? Should I post the code?

Thanks.
Rich Hollenbeck



嗯,真正的问题是你是尝试不正确地使用查询。


首先,无论何时,只要使用参数而不是字符串插入。

这允许数据库库来处理问题对于你以及

自动处理值和空值之间的差异等。


在你不能使用参数的情况下,确保你总是预先处理字符串
,以便它可以正确地插入到SQL中......


....

strSql =" SELECT *" &安培; _

" FROM tblPerson" &安培; _

" WHERE tblPerson.Name =" &安培; TextToSqlConstExpr(" James O''Connel")

....


公共函数TextToSqlConstExpr(Text as String)As String

Const cstrQuote ="''"

TextToSqlConstExpr = cstrQuote& _

替换(文本,cstrQuote,cstrQuote& cstrQuote)& _

cstrQuote

结束函数


字符串值数据不与doubled单引号一起存储。

格式正确的字符串是在SQL命令字符串

构建的同时生成的。


星期二,10月5日2004 16:51:59 GMT,Richard Hollenbeck

< ri **************** @ verizon.net>写道:
Well, the real problem is that you are trying to use queries improperly.

First of all, whenever you can, use parameters instead of string insertion.
This allows the database library to handle the issue for you as well as
automatically handling the difference between a value and a Null, etc.

In the cases when you can''t use parameters, make sure you always pre-process
the string, so that it can be inserted into the SQL properly, ...

....
strSql = "SELECT * " & _
"FROM tblPerson " & _
"WHERE tblPerson.Name=" & TextToSqlConstExpr("James O''Connel")
....

Public Function TextToSqlConstExpr(Text As String) As String
Const cstrQuote = "''"
TextToSqlConstExpr = cstrQuote & _
Replace(Text, cstrQuote, cstrQuote & cstrQuote) & _
cstrQuote
End Function

The string value data is not stored with the doubled single-quote. The
properly formatted string is generated at the same time the SQL command string
is built.

On Tue, 05 Oct 2004 16:51:59 GMT, "Richard Hollenbeck"
<ri****************@verizon.net> wrote:
为了防止未来的撇号错误和错误,
禁止撇号进入文本字段是不是更简单?例如,
不能爱丽丝的餐厅。改为Alices Restaurant
在数据输入期间自动和以编程方式?当我将字符串基于
查询时,这将消除我的连接字符串产生错误。认为这是Dreaded Apostrophe Bug的一个例子。如果我输入双撇号,我仍然会在StrSQL中得到错误。此外,它作为一个双撇号出现在现场,这比一个缺少的撇号更丑。

这是一个简单的电话簿。想法?我应该发布代码吗?

谢谢。
Rich Hollenbeck
To prevent future apostrophe bugs and errors, isn''t it just simpler to
forbid an apostrophe from being entered into a text field? For example,
couldn''t "Alice''s Restaurant" be changed to "Alices Restaurant" etc.
automatically and programmatically during data entry? This would eliminate
my concatinated strings from producing errors when I base the string on a
query. Think this is an example of the "Dreaded Apostrophe Bug." If I
enter a double apostrophe I still get the error in the StrSQL. Also, it
appears in the field as a double apostrophe which is uglier than a missing
apostrophe.

This is for a simple phone book. Ideas? Should I post the code?

Thanks.
Rich Hollenbeck






这篇关于如何禁止文本框中的撇号(输入掩码?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆