URGENT!!!!delete child record and later delete the parent record
Hi,
I am using a for to delete records from the tables in access 2000 that are linked to oracle 9i. Now, I am trying to delete the child records from other tables, then the user tries to delete the parent record from the parent table.
But, I am unable to do that as I am getting errors from access as "ODBC-call failed" <parent table > integrity constraint <key> ..
I cannot use the relationship properties for cascade delete and stuff because, my tables are linked to oracle tables and when I see the relationships, I don't have the option of selecting those features.They are disabled. So I need vba code to link to a command button, in this case I am using this code for a command button delete in the parent table form. So if hte user clicks this button all the related child records are deleted and then the parent record will be deleted. Ofcourse, that is not happenning with the code that I wrote
Please let me know where I am going wrong and what should I do to..
Thanks,
Here is my code.
--------------------------------------------
Private Sub DELETE_RECORD_CMDB_Click()
On Error GoTo Err_DELETE_RECORD_CMDB_Click
DoCmd.SetWarnings False
Dim Response As Integer
Dim Str, Str1, PART_CODE As String
PART_CODE = Me.PART_CODE
Response = MsgBox("Do you want to delete PART CODES from all child tables?", vbYesNo, "Continue")
If (Response = vbYes) Then
DoCmd.SetWarnings False
Str = "Delete * FROM SUPPLIER WHERE PART_CODE = '" & Me.PART_CODE & " ';"
CurrentDb.Execute Str, dbFailOnError
Str1= "Delete * from PLANT WHERE PART_CODE = '" & Me.PART_CODE & "';"
'CurrentDb.Execute Str1, dbFailOnError
Docmd.runSQL Str1
' delete the record from form
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
Else
MsgBox "Cannot delete this record. To delete this record, please delete the same record in the child tables,which are PLANT and SUPPLIER"
End If
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
DoCmd.SetWarnings True
Exit_DELETE_RECORD_CMDB_Click:
Exit Sub
Err_DELETE_RECORD_CMDB_Click:
MsgBox Err.Description
Resume Exit_DELETE_RECORD_CMDB_Click
End Sub
Hi,
I am using a for to delete records from the tables in access 2000 that are linked to oracle 9i. Now, I am trying to delete the child records from other tables, then the user tries to delete the parent record from the parent table.
But, I am unable to do that as I am getting errors from access as "ODBC-call failed" <parent table > integrity constraint <key> ..
I cannot use the relationship properties for cascade delete and stuff because, my tables are linked to oracle tables and when I see the relationships, I don't have the option of selecting those features.They are disabled. So I need vba code to link to a command button, in this case I am using this code for a command button delete in the parent table form. So if hte user clicks this button all the related child records are deleted and then the parent record will be deleted. Ofcourse, that is not happenning with the code that I wrote
Please let me know where I am going wrong and what should I do to..
Thanks,
Here is my code.
--------------------------------------------
Private Sub DELETE_RECORD_CMDB_Click()
On Error GoTo Err_DELETE_RECORD_CMDB_Click
DoCmd.SetWarnings False
Dim Response As Integer
Dim Str, Str1, PART_CODE As String
PART_CODE = Me.PART_CODE
Response = MsgBox("Do you want to delete PART CODES from all child tables?", vbYesNo, "Continue")
If (Response = vbYes) Then
DoCmd.SetWarnings False
Str = "Delete * FROM SUPPLIER WHERE PART_CODE = '" & Me.PART_CODE & " ';"
CurrentDb.Execute Str, dbFailOnError
Str1= "Delete * from PLANT WHERE PART_CODE = '" & Me.PART_CODE & "';"
'CurrentDb.Execute Str1, dbFailOnError
Docmd.runSQL Str1
' delete the record from form
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
Else
MsgBox "Cannot delete this record. To delete this record, please delete the same record in the child tables,which are PLANT and SUPPLIER"
End If
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
DoCmd.SetWarnings True
Exit_DELETE_RECORD_CMDB_Click:
Exit Sub
Err_DELETE_RECORD_CMDB_Click:
MsgBox Err.Description
Resume Exit_DELETE_RECORD_CMDB_Click
End Sub
Last edited: