catching if some one wants to delete records

megatronixs

Registered User.
Local time
Today, 21:43
Joined
Aug 17, 2012
Messages
719
Hi all,

I managed to create some code that will prevent someone from deleting records. It will give message the they are not allowed to deleter records and then it will write to a table the user name, date and time, record ID and team ID.
This works great when it is only one record, but when they select multiple records (from the datasheet view subform), it will only remember the selected one no matter how many they selected.

Is there a way that the below code can be adjusted to catch them all?
Code:
Private Sub Form_Delete(Cancel As Integer)
 
    Cancel = True
    MsgBox "You are not allowed to delete records."
 
    Dim strSqlrevidcheck As String
    Set rst = Nothing
 
 Call GetUserName
 
 user_deleting = GetUserName
 
    DoCmd.SetWarnings False
    strSqlrevidcheck = "Insert Into  tbl_silent (record_id, user_deleting, date_try_delete, team_id) Values (user_id, GetUserFullName(), Now(), GetUserTeamID())"
    DoCmd.RunSQL strSqlrevidcheck
    DoCmd.SetWarnings True
 
End Sub

Greetings.
 
You have get username 3 times.
The 1st one CALL get username, is not needed, it doesn't do anything.
The 2nd pulls the name, ok, but isn't used in the SQL.
The SQL has a different getuserfullname. You only need 1 getuser function.

As to the delete. Have a form where user cannot delete ANY records. Allow them to check mark the ones to delete.
Then the query that pulls the marked records,would first write to the log with append qry, then the delete qry would run.
 
I Ranman256,

I'm aware of the GetUserName, just was to busy to delete it from the code.
Only the Admins should be able to delete the duplicates. I just wanted to catch if some one is deleting this on purpose.

Greetings.
 
remove the line:

Cancel = True

because this will cancel preparation for deletion process for the rest of records to be deleted.
move your Cancel and messagebox to BeforeDeleteConfirm event:

Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
Cancel = True
Msgbox "You are not allowed to delete records."
End Sub
 
Hi,
I will try this as soon as I'm back at work.

Greetings.
 

Users who are viewing this thread

Back
Top Bottom