validation - 访问 - 基于 ID 和日期的验证
问题描述
我正在为食品银行业务构建一个小型 Access 数据库,作为一个班级的项目。以下是我的一张表:
订单(订单 ID、家庭 ID、订单日期、交付日期)
我将如何设置仅允许家庭 (householdID) 每个日历月下一个订单 (orderDate) 的数据验证规则?这是否仅适用于该表中的验证规则?
在此先感谢您的帮助。
解决方案
Will need to use VBA, either in BeforeUpdate event of orderDate textbox or BeforeUpdate event of form. Could use DLookup() expression. Something like:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not IsNull(DLookup("householdID", "Order", "Format([OrderDate], 'yyyymm')=" & Format(Me.tbxDate, "yyyymm"))) Then
Cancel = True
MsgBox "Household already has order for this month."
DoCmd.RunCommand acCmdUndo
End If
End Sub
Might also be possible to use table BeforeChange data macro, however, I don't use macros of any type.
推荐阅读
- loops - 使用矩阵后如何在循环中提取系数和 CI 以创建具有多年系数和 CI 的双向图
- c - 如何打印 gcc 默认对齐编号?
- php - PHP - Praneeth Madush Advanced-PHP-Login-System 脚本安全吗?
- android - 如何将 DEX 版本更改为 37,同时将 targetSdkVersion 保持在 30?
- python-3.x - 在 Pytest 固定装置内使用时,Python 日志不会记录
- debugging - b-table (Firefox) 上的图形错误
- asp.net-core - 是否可以有一个集线器的单例实例?
- python - Python json通过特定键值在列表中查找字典
- javascript - 如果选中,则获取图像的 url
- python - Python打印不同的值