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 record and relationship records using kill

Status
Not open for further replies.

oxicottin

Programmer
Jun 20, 2008
353
US
First im in no way a programer and I cant figure out how to chang that to newbie....

I have a form (frmVWI) with a subfrm (frmVWISubform) and on the form I have a delete button
that I have to delete the images that are stored in a folder outside the database. The subfom
has a table called tblJobSteps which has a field called (ImagePath) and when a path is saved it
looks like (\VWI_Images\1.jpg). anyways I had someone help me with what I have now but its not
doing anything. Oh and there might be several images associated with the record thats why it needs to
loop threw each one and kill the image. Any thoughts?

Code:
Private Sub cmdKillDelete_Click()

Dim rst As DAO.Recordset
Dim strTableName As String
Dim strSQL As String

strSQL = "Select * From tblJobSteps Where JobStepID = " & Me!VWIID
 Set rst = CurrentDb.OpenRecordset(strSQL)
    
Do Until rst.EOF
    If Dir(rst!ImagePath) <> "" Then
       Kill (rst!ImagePath)
    End If
    
    rst.MoveNext
Loop

rst.Close
Set rst = Nothing

End Sub

Thanks,
SoggyCashew.....
 
You have to work it backwards to see why it is not working.
The kill command should work assuming it is passed a valid file path. So first question is, "is the path being passed valid". Check that with the following, and then post back the immediate window results.

If Dir(rst!ImagePath) <> "" Then
debug.print "Path = " & rst!imagePath
Kill (rst!ImagePath)
End If


 
Majp, how do you get the immediant window results? I know where it is and can bring it up but what then? I changed the code because it wasnt finding the full path. Now it does delete the first image and doesnt loop. Any thoughts?

Code:
Private Sub cmdKillDelete3_Click()

Dim rst As DAO.Recordset
Dim strTableName As String
Dim strSQL As String
Dim dbPath
    
dbPath = Application.CurrentProject.Path
 strSQL = "Select * From tblJobSteps Where JobStepID = " & Me!VWIID
  Set rst = CurrentDb.OpenRecordset(strSQL)
    
Do Until rst.EOF
    If Dir(dbPath & rst!ImagePath) <> "" Then
       Kill (dbPath & rst!ImagePath)
    End If
    
    rst.MoveNext
Loop

rst.Close
Set rst = Nothing

End Sub

Thanks,
SoggyCashew.....
 
How are ya oxicottin . . .

According to you:
oxicottin said:
[blue]The subfom
has a table called tblJobSteps which has a field called (ImagePath) and [blue]when a path is saved it
looks like[/blue] ([red]\VWI_Images\1.jpg[/red])[/blue]
What about the [blue]drive letter![/blue] The path is not fully qualified without it!

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Good TheAceMan1, It gives me the full path including drive and deletes the first image but only loops threw once and I have 3 images. Any sugestions?

Oh, look at last post I added the dbPath.... :)

Thanks,
SoggyCashew.....
 
I got it working I had the sql wrong... Thanks!

Thanks,
SoggyCashew.....
 
oxicottin . . .

Perhaps you can show your resloved SQL for others who were following this thread! [thumbsup2]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top