如何防止基于多个字段的重复 [英] How to prevent duplicate based on more than one field

查看:70
本文介绍了如何防止基于多个字段的重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表格基于以下列名称的表格:


OrderID PK(自动编号),OrderNo,customer_id


OrderNo和coustomer_id是必填字段


您可以拥有相同的客户,订购一次。

例如:

1,123, tri-g允许

我的问题是,对于orderno与客户,我想在进入表单时防止重复。

我不能把所有字段都设为主键,因为如上所述,这会导致客户与orderno重复。


无论如何要防止当用户输入

副本(带有orderno的customer_id,我想要弹出消息框说明重复顺序?

解决方案

< blockquote> @mseo


首先mseo .....请不要在一天内复制你的帖子!!它是浪费其他人的时间来管理这个。我已经删除了你在这个问题上的其他类似措辞的帖子。给予足够的时间没有回复之前重新发布


在这种情况下,想法是检查表中所有预先存在的值并计算主键基于OrderNo和Customer的标准组合的值。如果返回值大于零,则撤消当前记录编辑。


以下方法预先假定您的OrderID和Customer_ID是TEXT字段而不是数字作为撇号用于包装字段内容。如果是数字则只删除撇号。


以下将使用基于名为tblOrders的表格的表单的beforeupdate属性中的 DCount 函数来实现这一点

展开 | 选择 | Wrap | 行号


谢谢你,Jim Doherty为你回复


表字段的数据类型为以下:

OrderID PK - 自动编号

OrderNo文本

Customer_ID编号

所以我修改了你的代码,删除了customer_id部分的单引号

但是当我运行代码时, msgbox触发运行错误3075

展开 | 选择 | Wrap | 行号


@mseo

您最终将了解字符串的所有引号,或者不知道数字何时何地定义它们等等但是您所做的修改不是现在语法可行的。你在错误的地方删除它应该是这个Dcount函数。

展开 | 选择 | Wrap < span class =codeDivider> | 行号


I have form based on table with following column name:

OrderID PK (autonumber), OrderNo, customer_id

OrderNo and coustomer_id are required fields

You are allowed to have Same customer, orderno one time.
For example:
1, 123 , tri-g allowed
My questions is that, for orderno with customer, I would like to prevent duplicates when entering in the form.
I can''t make all the fields primary key because, as stated above that would cause duplication the customer with orderno.

Is there anyway to prevent duplicates for and when the user enters the
duplicates (customer_id with orderno, I would like to have message box pop up saying Duplicate order ?

解决方案

@mseo
Firstly mseo..... please do not duplicate your posts within a day of each other!! it is a waste of other peoples time administering for this. I have deleted your other similarly worded posting on this issue. Give sufficient time to elapse without response before reposting

The idea in this instance would be to examine all pre-existing values in your table and to count the primary key value based on criteria combination of OrderNo and Customer. Where the return value is greater than zero then undo the current record edit.

The following methods pre-suppose that your OrderID and Customer_ID are TEXT fields as opposed to numeric as apostrophes are used in wrapping field contents. If numeric then merely remove the apostrophes.

The following will do that using the DCount Function in the beforeupdate property of the form based on a table called tblOrders

Expand|Select|Wrap|Line Numbers


thank you, Jim Doherty for you reply

the datatype of the table fields as the following:
OrderID PK - autonumber
OrderNo text
Customer_ID Number
so I modified your code by removing the single quote of the customer_id part
but when I run the code, msgbox fires with run-error 3075

Expand|Select|Wrap|Line Numbers


@mseo
you eventually will get your head around all the quotes for strings or none for numbers where and when to define them and so on but the amendments you made are not now syntax viable. You removed in the wrong places it should be this for that Dcount function.

Expand|Select|Wrap|Line Numbers


这篇关于如何防止基于多个字段的重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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