Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete images outside DB

Status
Not open for further replies.

oxicottin

Programmer
Jun 20, 2008
353
US
Hello, Im kinda new and im using access 07 and I want to delete images outside the DB. I have form (frmVWI) with a subform (frmVWISubform)and I they have a relationship and linked child fileds. The subform is a continious form that shows images and saves the images link to a table so it can show on my form. If I add a delete button on my form it delets all records accociated with that record and thats what I want except it doesnt delete the images from my image folder. I do however have a button on each row in the continious subform that is a delete button and it uses a "Kill" process that delets the image. How can i incorporate that into my other button? Here is the code for the one that delets the single image. I found most of the code on the net so I really dont know how the "kill" works. Thanks!


Code:
Private Sub cmdImg_Remove_Click()

On Error GoTo Err_cmdImg_Remove_Click

    Dim Msg, Msg2, Style, Style2, Title, Response
    Dim dbPath
    
    dbPath = Application.CurrentProject.Path
    
    ' save the current image in case user changes mind
    OriginalImagePath = Me!ImagePath

    ' set the variables for the message boxes
    Msg = "Remove image?" & Chr(13) & Chr(13) & "Will delete file: " & Chr(13) & Chr(13) & dbPath & OriginalImagePath
    Style = vbYesNo + vbQuestion + vbDefaultButton2
    Msg2 = "No image to remove"
    Style2 = vbOKOnly + vbInformation
    Title = "Image Removal"
    
    ' make sure there is a photo there to remove
    If IsNull(Me!ImagePath) Then
        ' no photo exists, so let the user know one cannot be removed
        MsgBox Msg2, Style2, Title
    Else
        ' a photo exists, so ask whether user is sure
        Response = MsgBox(Msg, Style, Title)
    
       If Response = vbYes Then
           ' user wants to remove, so remove photo
           Me![ImagePath] = ""
           Me!imgJobStep.Picture = ""
           Kill (dbPath & OriginalImagePath) 'deletes image in VWI_Images folder
           Me.Requery 'Refresh form
           txtUnboundImagePath.Requery 'Refresh text box
       Else
           ' user wants to keep, so restore originial
           Me![Image] = OriginalImagePath
           Me!imgJobStep.Picture = dbPath & Me![Image]
       End If
    End If

Exit_cmdImg_Remove_Click:
    Exit Sub

Err_cmdImg_Remove_Click:
        Msg = "Error # " & Str(Err.Number) & Chr(13) & Err.Description
        MsgBox Msg, vbOKOnly, "Bacterial Pathogenesis", Err.HelpFile, Err.HelpContext
    Resume Exit_cmdImg_Remove_Click
    
End Sub


Thanks,
SoggyCashew.....
 
If I add a delete button on my form it delets all records accociated with that record and thats what I want
So, why not just copy the code you show into the delete button code?

Randy
 
That code is on the forms subform which is a continuous form so I might have one record on my frmVWI but that forms relationship with the subform has 10 records with links to images. If I just put a delete button on my form it deletes everythig except for the images that are stored in my folder. Oh and im not a programer im a newbie I just figure out how to change that in my title...

Thanks,
Chad

Thanks,
SoggyCashew.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top