防止ms访问表中的重复条目

问题描述

我是不熟悉ms访问的人,我已经为要应用重复入学限制的学校准备了一个数据库

我想在同一个月停止重复输入。 <div class=" frame frame-default frame-type-textmedia frame-layout-0" id="c47903"><a id="c47904"/><div class="ce-textpic ce-left ce-above"><div class="ce-bodytext"><p>The latest data of the evolution of COVID-19 over the past 24hours <strong>in Québec</strong> reveal:</p><ul><li>87new cases,bringing the total number of infected persons to61,004;</li><li>no deaths have occurred in the past 24hours,to which are added 3deaths which occurred between August7 and12,for a total of5,718;</li><li>the number of hospitalizations increased by2 compared to the prevIoUs day,for a cumulative total of151. Of these,25were in intensive care,an increase of2;</li><li>18,596tests were performed on August12,for a cumulative total of1,428,286.</li></ul></div></div></div> 的类型是数字,而月份与另一个类型为文本的表链接时。我尝试了许多选项,但发生类型不匹配错误。数据是从表单输入的,我需要在表单更新时应用验证

studentID

我想添加月份条件以记录一个月一次的学生费用。

解决方法

文本字段参数需要用撇号定界符(日期/时间使用#字符)。考虑:

x = DCount("StudentID","tblFeeVoucherGenerate","StudentID =" & Me.StudentID & _
     " AND MonthFieldName='" & Me.tbxMonth & "'")

月份是保留字-建议不要将其用作字段名称。

,

DCount函数不会跨表,如果表很大,则可能会变慢。 考虑进行查询以联接名为qryFeeVoucherGenerate

的表
SELECT tblFreeVoucherGenerated.StudentID AS StudentID,tblWithNameOfDateField.NameOfDateFiled AS NameOfDateField FROM tblFreeVoucherGenerated
LEFT JOIN
tblWithNameOfDateField 
ON tblFreeVoucherGenerated.StudentID = tblWithNameOfDateField.StudentID
WHERE DATEDIFF( 'm',tblWithNameOfDateField.DonationDate,Date()) = 0;

使用名称qryFeeVoucherGenerated保存上述查询,然后使用:

 Private Sub StudentID_AfterUpdate()

'If you decide to create a textbox for the DateField the use:
'DCount("*","[qryFeeVoucherGenerate]","[StudentID] = '" & Me.StudentID.Value & "' AND CDATE([NameOfDateField]) = '" & Me.NameOfMonthFiled.Value & "'") > 0

 If DCount("[StudentID]","[StudentID] = '" & Me.StudentID.Value & "'") > 0 Then

 MsgBox "Fee Already Recorded for this month"
 Me.Undo
 Exit Sub
 End If

 MsgBox "Record has been Saved"
 DoCmd.RunCommand acCmdRecordsGoToNew

 End Sub