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 SQL not working correctly.

Status
Not open for further replies.

oxicottin

Programmer
Jun 20, 2008
353
US
Hello, I have two problems and cant figure out whey they dont work now.

First, I have a form with a subform and on the subform there is a delete button that is suposed to delete an image "If there is one" and then the record. The subform is a continious subform.
Whats happening is when I click the delete button on a record that includes an image everything works like its suposed to but if I click on a record that doesnt include an image it does nothing, it wont even delete the record. Can someone please show me whats missing or incorrect in the VBA.

Code:
Private Sub cmdDeleteStep_Click()
    
Dim strMsg As String
Dim dbPath

'Finds BE path in module-modGetPath
dbPath = GetCurrentPath()

OriginalImagePath = Me!ImagePath

strMsg = "Are you sure you want to delete this Job Step?" & Chr(13) & _
         "" & Chr(13) & _
         "" & _
         "This job step and image will be deleted if (Yes) is selected!!!"
        
If MsgBox(strMsg, vbCritical + vbYesNo) = vbYes Then
   Me![ImagePath] = ""
    Me!imgJobStep.Picture = ""
      'If Len(Dir(dbPath & OriginalImagePath)) > 0 Then 'Check to see if there is an image
         Kill (dbPath & OriginalImagePath)             'If so then delete it.
      'End If
   DoCmd.RunCommand acCmdDeleteRecord ' Delete the record
    Forms![frmVWI]![frmVWISubform].Requery ' Refresh subform
 End If
End Sub

Second, I have a delete button on the form and it deletes the record and its records that are accociated with the record. When I click the button it seems as if it did nothing but in fact it deletes the images associated with the record BUT doesnt delete the record.

Code:
Private Sub cmdKillDelete_Click()

Dim rst As DAO.Recordset
Dim strSQL As String
Dim strDeleteVWI As String
Dim dbPath
Dim strPasswd

If IsNull(Me.txtVWIID) Then
 MsgBox "There is no data or record to delete!", vbInformation, "No Data"
  Exit Sub
   End If

   
If MsgBox("Are you sure you want to delete this record?" & _
 "There is no way to recover this if you say 'Yes'.", vbQuestion + vbYesNo, "Confirm Delete Record") = vbYes Then
 
'Finds BE path in module-modGetPath
dbPath = GetCurrentPath()

 strSQL = "Select * From tblJobSteps Where VWIID = " & Me!VWIID
  Set rst = CurrentDb.OpenRecordset(strSQL)
    
Do Until rst.EOF
 If Dir(dbPath & rst!ImagePath) <> "" Then 'Verifies if image path is there
   Kill (dbPath & rst!ImagePath)           'Deletes Image in folder /VWI_Images
    End If
     rst.MoveNext
Loop

'Deletes record from tblJobSteps
    strSQL = "Delete * From tblJobSteps Where VWIID = " & Me!txtVWIID
     CurrentDb.Execute strSQL, dbFailOnError
'Deletes record from tblVWI
     strDeleteVWI = "Delete * From tblVWI Where VWIID = " & Me.txtVWIID
      CurrentDb.Execute strDeleteVWI, dbFailOnError
     
     Me.Requery
       
MsgBox "Deletion Complete", vbInformation, "Delete Confirmed"
 DoCmd.Close 'Close the frmVWI

    rst.Close
     Set rst = Nothing
     
    End If
End Sub




I have a form with a subform and on the subform there is a delete button that is suposed to delete an image "If there is one" and then the record. The subform is a continious subform.

Whats happening is when I click the delete button on a record that includes an image everything works like its suposed to but if I click on a record that doesnt include an image it does nothing, it wont even delete the record. Can someone please show me whats missing or incorrect in the VBA.



Thanks,
SoggyCashew.....
 
I set the breakPoints and it stoped at

Kill (dbPath & OriginalImagePath)

And it gave an runtime error 53. I moused over the line and it said that OriginalImagePath was null which it was. The code is suposed to skip over that if its null and then delete the record but stops on that line. How do I fix that?



Thanks,
SoggyCashew.....
 
If Dir(dbPath & rst!ImagePath) <> ""

This is not the same as NULL.
Perhaps this?
Code:
If Dir(dbPath & rst!ImagePath) <> ""  or IsNull(Dir(dbPath & rst!ImagePath))

Randy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top