Search code examples
ms-accessms-access-2016

How to create a Validation rule that makes field3 not equal to field2 in a table


I'm using MS-Access 2016. I had created a table1 with few fields. Then I created Table2. where my Field2 of table2 is having the source from Field3 of table1. then in field3 of a table2, I want to have validation rule where the Field3 of table2 should no be equal to Field 2 of table2.


Solution

  • I want to have validation rule where the Field3 of table2 should no be equal to Field 2 of table2.

    You can use a table-level Validation Rule for that.

    1. Open table2 in Design View.
    2. Right-click the table's title area and open its property sheet.
    3. Add [Field3]<>[Field2] in the box next to Validation Rule.
    4. Save the table design, switch to Datasheet View, and edit values to confirm the validation is enforced as you intend.

    The situation may be more complicated if your table design permits Nulls for both those fields.
    The Validation Rule above will accept a row with Null in both those fields. But, if you want the fields to be considered equal (and therefore invalid) when both contain Null, use this instead:

    [Field3]<>[Field2] And Not ([Field2] Is Null And [Field3] Is Null)