VB code to delete a file from Access DB.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wizardRahl
    New Member
    • Oct 2006
    • 40

    VB code to delete a file from Access DB.

    Hello,

    I have a problem with a block of code I'm trying to use that enables me to delete a file from not only the database, but the referenced folder in which the file is located.
    It will delete the file from the database (removes the picture from the form), but doesn't permantely remove the file. Here's what I have:

    Private Sub Form_AfterDelCo nfirm(Status As Integer)
    Dim DeleteFilename As String
    If Status = acDeleteOK Then
    If Len(DeleteFilen ame) > 0 Then
    Dim DeleteImgPath As String
    DeleteImgPath = GetImageFolder & "Images\" & DeleteFilename

    ' Delete the image file if it exists
    If Dir(DeleteImgPa th) <> vbNullString Then Kill DeleteImgPath
    End If
    End If

    DeleteFilename = ""
    End Sub


    This is a subForm amongst other code that I have. Also, I get a complier error - mismatch type for the ampersand on the 6th line of code.....
    Any insight anyone could give would be most appreciated.
    Thanks in advance.
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Originally posted by wizardRahl
    Hello,

    I have a problem with a block of code I'm trying to use that enables me to delete a file from not only the database, but the referenced folder in which the file is located.
    It will delete the file from the database (removes the picture from the form), but doesn't permantely remove the file. Here's what I have:

    Private Sub Form_AfterDelCo nfirm(Status As Integer)
    Dim DeleteFilename As String
    If Status = acDeleteOK Then
    If Len(DeleteFilen ame) > 0 Then
    Dim DeleteImgPath As String
    DeleteImgPath = GetImageFolder & "Images\" & DeleteFilename

    ' Delete the image file if it exists
    If Dir(DeleteImgPa th) <> vbNullString Then Kill DeleteImgPath
    End If
    End If

    DeleteFilename = ""
    End Sub


    This is a subForm amongst other code that I have. Also, I get a complier error - mismatch type for the ampersand on the 6th line of code.....
    Any insight anyone could give would be most appreciated.
    Thanks in advance.
    line 8 does indeed contain an error
    DeleteImgPath = GetImageFolder & "Images\" & DeleteFilename

    When you are returning a value from a function you need to include the parentheses:

    DeleteImgPath = GetImageFolder( ) & "Images\" & DeleteFilename

    Comment

    Working...