Results 1 to 2 of 2
  1. #1
    Join Date
    May 2004
    Posts
    133

    Talking Unanswered: prevent deleting record from datasheet-view

    Heeeeeeeelp meeeeee!
    I have a database split, backend file are placed in server's sharing folder so that multi-users can access to it
    and work as a workgroup.
    I planned that: User can delete only record that created by him. And user can not delete record that created by other user.
    I form-view form, I added "delete" button" with this code in onclick event:
    Private Sub delete_cmd_Click()

    On Error GoTo Err_delete_cmd_Click
    If fOSUserName = Me.createdby Then

    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
    Else
    MsgBox fOSUserName & ", you are not allowed to delete this record." & vbCrLf & _
    "Please email this record to " & Me.createdby & " and request to delete.", _
    vbCritical + vbOKOnly, "G8 comters warning!"
    Exit Sub
    End If

    Exit_delete_cmd_Click:
    Exit Sub

    Err_delete_cmd_Click:
    MsgBox Err.Description
    Resume Exit_delete_cmd_Click
    End Sub

    It worked for me. But when I added this code to before del confirm event of form and switch to datasheet-view
    form, performed deleting action, my message "you are not allowed to delete this record" appeard. But when
    I clicked OK, it deleted record created by other user, not by me.
    Any idea?
    many thanks

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    Try it this way......

    For your Delete button:

    Code:
    Private Sub delete_cmd_Click()
       On Error Resume Next
       DoCmd.SetWarnings False
       DoCmd.RunCommand acCmdDeleteRecord
       DoCmd.SetWarnings True
       Err = 0
    End Sub
    Instead of using the Before Del Confirm event, place your code into the OnDelete event like this:

    Code:
    Private Sub Form_Delete(Cancel As Integer)
       If fOSUserName <> Me.createdby Then
    	  MsgBox fOSUserName & ", you are not allowed to delete this record." & _
    			 vbCrLf & "Please email this record to " & Me.createdby & _
    			 " and request to delete.", vbCritical + vbOKOnly, "G8 comters warning!"
    	  Cancel = True
       End If
    End Sub
    Now it doesn't matter which view you are in.

    .
    Environment:
    Self Taught In ALL Environments.....And It Shows!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •