Eliminar registro de tablas relacionadas Hola amigos, estoy tratando de eliminar registros de dos tablas relacionadas asi
Private Sub cmd_Eliminar_Click()
Dim i As Integer
For i = ListView1.ListItems.Count To 1 Step -1
If ListView1.ListItems(i).Selected Then
'Establecer ruta de conexión
sBase = App.Path & "\" & "Productos.mdb"
Tabla = "Ingresos"
Tabla2 = "Precios"
' Crear los objetos
Set cnn = New adodb.Connection
Set rst = New adodb.Recordset
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & sBase
s = "SELECT Id_ingreso,Fecha,Codigo,Descripcion,Cantidad,Cunit ario,Ctotal,Id_precio,Id_ingresoP,PrecioDetalle,Page Ranking ecioDocena FROM " & Tabla & ", " & Tabla2 & " WHERE " & Tabla2 & ".Id_ingresoP= " & Tabla & ".Id_ingreso AND " & Tabla & ".Id_ingreso=Val('" & lbl_ID.Caption & "') AND Codigo='" & ListView1.ListItems(i).SubItems(2) & "'"
rst.Open s, cnn, adOpenDynamic, adLockOptimistic
With rst
If (.BOF And .EOF) Then
MsgBox "No existe ningún registro", vbInformation
Exit Sub
Else
If MsgBox("Esta seguro de eliminar este item", vbExclamation + vbOKCancel, "ADVERTENCIA") = vbOK Then
rst.Delete
MsgBox "PRODUCTO ELIMINADO", vbInformation
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
Else
Exit Sub
End If
End If
End With
End If
Next i
End Sub
Pero me dice que no puede porque la tabla Precios tiene registros relacionados, lo que es efectivo, pero no se como hacer dichosa consulta para que elimine de ambas
poe favor si es posible me iluminen se los agradecere hasta el infinito
Cursor |