Protect a single record

Numpty

on t'internet
Local time
Today, 09:18
Joined
Apr 11, 2003
Messages
60
IS there anyway to protect a single record so that it cannot be deleted?

The main way a user would delete a record would be from a button on the form - I've coded the button so it's disabled when that particular record comes up but the user could select the delete record option from the Edit menu. I don't know how to go about disabling that without taking out the whole menu.

Any pointers greatly appreciated.

Cheers
 
How about using the Before Del Confirm and After Del Confirm events to trap record deletions on the form?
 
you could run a check on what's being deleted using the 'before delete confirm' setting in the form's properties, and then cancel the delete if it is the one you're trying to protect.

Also, you could add a 'do not delete' field flag on the base table that you set yourself and this way you could protect numerous records by checking for this flag vefore deleting.
 
If you can determine which record or records you do not want to delete. You can use the Form_Current Event and set the Form.AllowDeletions property. Test for the desired record or records and set the property.

Here's a test with a prompt you can try yourself


If MsgBox("Lock Deletions", vbYesNo, "TEST") = vbYes Then
Me.AllowDeletions = False
Else
Me.AllowDeletions = True
End If


Good Luck. Let me know how it works
 
Cheers for the replies.

I've put it into the On Delete event to check for the ID of the particular record.

Works fine.

Thanks
 
Here is a solution that will work regardless of how a user tries to delete the record. This solution will work even if someone links to the table and tries to delete the record from C++.

Create a new table with a name that starts with USys. This will enable you to hide the table from casual view. Add a single row with an autonumber primary key and the key to the record you want to protect in the second field. Create a relationship between the two tables and select the enforce RI checkbox. Jet will now prevent you from deleting the protected row in the main table because there is a row in this "hidden" table that is related to it. When you're done, open the Tools/Options and check the hide user objects checkbox.
 

Users who are viewing this thread

Back
Top Bottom