A family of Microsoft relational database management systems designed for ease of use.
Can you explain the logic behind this? I'm wondering if there is not a better way.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I need to set my table/form to not allow duplicates, except for three commonly strings.
something like this primitive logic:
if string is not "abc" or "def" or "ghi" then
No duplicates for this field
end
*******
is this possible? If so, HOW?
Sue
A family of Microsoft relational database management systems designed for ease of use.
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Can you explain the logic behind this? I'm wondering if there is not a better way.
It can be done by applying a CHECK CONSTRAINT to the table. In Access this cannot be done directly in SQL view, however, but must be executed in code, which can be entered as a single line in the debug (aka 'immediate') window, which can be opened by pressing Ctrl+G. The statement would be as follows:
CurrentProject.Connection.Execute "ALTER TABLE YourTableName ADD CONSTRAINT SelectiveDuplication CHECK((SELECT YourColumnName FROM YourTableName WHERE NOT (YourColumnName = 'abc' OR YourColumnName = 'def' OR YourColumnName = 'gh1') GROUP BY YourColumnName HAVING COUNT(*)>1)IS NULL)"
To remove the CONSTRAINT you'd enter the following:
CurrentProject.Connection.Execute "ALTER TABLE YourTableName DROP CONSTRAINT SelectiveDuplication"
The table must be closed when either of the above are entered, and, if the database is split the statement must be executed in the back end, not the front end.