是(没有重复) [英] Yes(No Duplicates)

查看:81
本文介绍了是(没有重复)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设一张桌子有四个字段:

ID(PK)

Field1

Field2

Field3

字段1索引为是(无重复)

当在Field1中输入重复项时,在您尝试保存记录之前没有任何反应

记录然后出现此错误消息:

"您向表格请求的更改未成功,因为它们

将在索引,主键或

关系......"

这个错误信息是否会被困,并以某种方式说明复制

所在的字段是什么?


Jerry

解决方案

如果您通过表单输入数据,则可以使用表单的错误事件来

捕获错误并将其替换为您自己的错误。


这类事情:


公共函数FormError(frm作为Form,DataErr作为整数,响应为

整数)作为整数

如果DataErr = 3022然后

strMsg =" Field1的重复值。

MsgBox strMsg,vbCritical,无效数据

Response = acDataErrContinue

结束如果

结束功能

如果您有多个可能的重复字段,则需要使用

DLookup ()找到已经存在的那个。


-

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

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

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


" Jerry" < JS ***** @ nospam.please>在消息中写道

新闻:Jt ******************* @ newsread3.news.atl.eart hlink.net ...

说一个表有四个字段:
ID(PK)
Field1
Field2
Field3
字段1索引为是(无重复)
当在Field1中输入重复项时,在您尝试保存记录之前没有任何反应,然后会出现此错误消息:
您向表格请求的更改未成功因为他们会在索引,主键或
关系中创建重复的值......
可以捕获此错误消息并以某种方式说明重复的字段
在哪里?

Jerry



此外,创建一个额外的表格是一个很好的做法/>
用户只输入记录键以添加记录,这样您就可以在输入所有其他字段之前捕获

任何重复的键。


Allen Browne写道:

如果您通过表单输入数据,您可以使用表单的错误事件来捕获错误并将其替换为您自己的错误。

这类事:公共函数FormError(frm作为Form,DataErr作为整数,响应为整数)作为整数
如果DataErr = 3022那么
strMsg =" Field1的重复值。"
MsgBox strMsg,vbCritical,无效数据
响应= acDataErrContinue
结束如果
结束功能

如果您有多个可能的重复字段,则需要使用
DLookup()来查找已存在的字段。




我喜欢为此使用Form'的错误事件的方法,我将

建议Form_BeforeUpdate中的计数,每次保存记录时,这将计数

。以'错误事件'的形式表示

只有在出现问题时才会这样做。


-

[Oo = w = oO]


Say a table has four fields:
ID (PK)
Field1
Field2
Field3
Field 1 is indexed as Yes(No Duplicates)
When a duplicate is entered in Field1, nothing happens until you try to save
the record then this error message appears:
"The changes you requested to the table were not successful because they
would create duplicate values in the index, primary key or
relationship......"
Can this error message be trapped and somehow say what field the duplicate
is in?

Jerry

解决方案

If you enter data through a form, you can use the Error event of the form to
trap the error and replace it with your own.

This kind of thing:

Public Function FormError(frm As Form, DataErr As Integer, Response As
Integer) As Integer
If DataErr = 3022 Then
strMsg = "Duplicate value for Field1."
MsgBox strMsg, vbCritical, "Invalid data"
Response = acDataErrContinue
End If
End Function
If you have multiple possible duplicate fields, you will need to use a
DLookup() to find which one already exists.

--
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.

"Jerry" <js*****@nospam.please> wrote in message
news:Jt*******************@newsread3.news.atl.eart hlink.net...

Say a table has four fields:
ID (PK)
Field1
Field2
Field3
Field 1 is indexed as Yes(No Duplicates)
When a duplicate is entered in Field1, nothing happens until you try to
save
the record then this error message appears:
"The changes you requested to the table were not successful because they
would create duplicate values in the index, primary key or
relationship......"
Can this error message be trapped and somehow say what field the duplicate
is in?

Jerry



In addition, it''s a good practice to create an extra form where the
user enters only the record key for added records, so that you can trap
any duplicate keys before all the other fields are entered.


Allen Browne wrote:

If you enter data through a form, you can use the Error event of the form to
trap the error and replace it with your own.

This kind of thing:

Public Function FormError(frm As Form, DataErr As Integer, Response As
Integer) As Integer
If DataErr = 3022 Then
strMsg = "Duplicate value for Field1."
MsgBox strMsg, vbCritical, "Invalid data"
Response = acDataErrContinue
End If
End Function
If you have multiple possible duplicate fields, you will need to use a
DLookup() to find which one already exists.



I like the approach of using the Form''s error event for this, I would
suggested the counts in Form_BeforeUpdate, which would do the counts
every time a record is saved. Doing it in the form''s error event means
it''s only done if there''s a problem.

--
[Oo=w=oO]


这篇关于是(没有重复)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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