How to set a validation rule on a field in Access using SQL Query?

六眼飞鱼酱① 提交于 2019-12-06 03:48:28

I think you might be looking for the DLookup() function... This allows you to do a query type lookup in another table without writing code. How do I go about using DLookup in a validation rule of a text box on a form in access

But an important distinction here is that the DLookup() function is only available in the validation context at the form level, not the table level.

Depending on exactly where you are wanting to use the validation, this may give you a workable option for using query type lookups as part of your validation rules without writing code.

You're probably looking for a CHECK constraint:

ALTER TABLE NodeFamilyLink
ADD CONSTRAINT myConstraintName
CHECK (
   NOT EXISTS( SELECT 1 FROM NodeFamilyLink INNER JOIN NodeData ON NodeData.ParentID = NodeFamilyLink.NodeID)
)

Note that these can only be added through ADO (by using CurrentProject.Connection.Execute), or when the database is using ANSI-92 compatible syntax.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!