Results 1 to 6 of 6

Thread: Delete a file

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    Quetta-Pakistan
    Posts
    852

    Delete a file

    Hello,
    i want to delete my database using Kill App.Path & "\pcdb.mdb"
    but the error message cmoes "ACCESS DENIED"

    the full code is :

    Private Sub CmdRestore_Click()
    If Db.State = 1 Then
    Db.Close
    End If

    SetAttr App.Path & "\Pcdb.mdb", vbNormal
    Kill App.Path & "\pcdb.mdb"

    If Db.State = 0 Then
    On Error GoTo PerErr
    FileCopy Direc & "\" & FileName, App.Path & "\pcdb.mdb" '& Format(Date, "dd/mm/yyyy") & ".mdb"
    MsgBox "Restore completed ", vbInformation, "Restored"
    SetAttr App.Path & "\Pcdb.mdb", vbHidden

    PerErr: 'Access Permission (If Database is in use)
    If Err.Number = 75 Then
    MsgBox "Database is in use. Unable to create backup", vbCritical, "Database is in use"
    Exit Sub
    End If
    End If

    End Sub


    please help me

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Delete a file

    What other objects in your app is referencing/using the database?

    There may be also other applications (external) using the file such as an open MSAccess.

  3. #3
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Delete a file

    Try this
    VB Code:
    1. Private Sub CmdRestore_Click()
    2. On Error GoTo PerErr
    3. 'If Db.State = 1 Then
    4. 'Db.Close
    5. 'set db=nothing ' ---> new additon
    6. 'End If
    7. set db=nothing ' ---> new additon
    8. SetAttr App.Path & "\Pcdb.mdb", vbNormal
    9. Kill App.Path & "\pcdb.mdb"
    10.  
    11. 'If Db.State = 0 Then
    12.  
    13. FileCopy Direc & "\" & FileName, App.Path & "\pcdb.mdb" '& Format(Date, "dd/mm/yyyy") & ".mdb"
    14. MsgBox "Restore completed ", vbInformation, "Restored"
    15. SetAttr App.Path & "\Pcdb.mdb", vbHidden
    16.  
    17. Exit sub '--> New
    18.  
    19. PerErr: 'Access Permission (If Database is in use)
    20. If Err.Number = 75 Then
    21.   MsgBox "Database is in use. Unable to create backup", vbCritical, "Database      
    22.     is in use"
    23.    Exit Sub
    24.    End If
    25. 'End If
    26.  
    27. End Sub
    Last edited by danasegarane; Oct 7th, 2006 at 11:15 AM.

  4. #4

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    Quetta-Pakistan
    Posts
    852

    Re: Delete a file

    On Kill App.Path & "\pcdb.mdb", gives the error Permission Denied. Y ?

  6. #6
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Delete a file

    The file itself may have its permissions set to prevent delete if your using an OS with a filesystem with built in security.

    What's your operating system?

Posting Permissions

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



Click Here to Expand Forum to Full Width