Prevent users from editing a node if a CCK field has a specific value
What you want is probably a custom node_access module - just remember that permissions in Drupal are additive, so your custom module is granting permission, rather than taking it away. So, for instance, a user should not already have the "edit this content type" permission or they'll have it for ALL nodes of that content type.

Also, why even assume they can attempt to edit? If they don't have permissions to edit that page, short of them manually hitting the /edit URL for a node, they're not going to have a chance - no edit button will be visible.