J
JKarchner
I am trying to set up my form so that when i delete a record in one subform,
a similar record is deleted from another subform. Each subform uses a
different junction table and therefore i think i need to "search" for the
record prior to deletion. I get an error when i try to run it, saying that
the record cannot be deleted from those tables. Here is my code, i hope
someone can point me in the right direction:
Private Sub Form_Delete(Cancel As Integer)
If Me.SupplyPartCategory = "Window" Then
Dim SQL As String
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb()
SQL = "SELECT Model_ID, SupplyPart_ID FROM qryWWindowsXREFModels WHERE
qryWWindowsXREFModels.Model_ID = " & Me.Model_ID & " AND
qryWWindowsXREFModels.SupplyPart_ID = " & Me.SupplyPart_ID & ";"
'Set rst = db.OpenRecordSet(SQL, dbOpenDynaset)
Set rst = db.OpenRecordset(SQL)
If rst.RecordCount = 1 Then
SQL = "DELETE FROM (SELECT Model_ID, SupplyPart_ID FROM
qryWWindowsXREFModels WHERE qryWWindowsXREFModels.Model_ID = " & Me.Model_ID
& " AND qryWWindowsXREFModels.SupplyPart_ID = " & Me.SupplyPart_ID & ");"
DoCmd.RunSQL SQL
Me.Parent.[subFrmWQryWindows(New)].Form.Requery
End If
End If
End Sub
a similar record is deleted from another subform. Each subform uses a
different junction table and therefore i think i need to "search" for the
record prior to deletion. I get an error when i try to run it, saying that
the record cannot be deleted from those tables. Here is my code, i hope
someone can point me in the right direction:
Private Sub Form_Delete(Cancel As Integer)
If Me.SupplyPartCategory = "Window" Then
Dim SQL As String
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb()
SQL = "SELECT Model_ID, SupplyPart_ID FROM qryWWindowsXREFModels WHERE
qryWWindowsXREFModels.Model_ID = " & Me.Model_ID & " AND
qryWWindowsXREFModels.SupplyPart_ID = " & Me.SupplyPart_ID & ";"
'Set rst = db.OpenRecordSet(SQL, dbOpenDynaset)
Set rst = db.OpenRecordset(SQL)
If rst.RecordCount = 1 Then
SQL = "DELETE FROM (SELECT Model_ID, SupplyPart_ID FROM
qryWWindowsXREFModels WHERE qryWWindowsXREFModels.Model_ID = " & Me.Model_ID
& " AND qryWWindowsXREFModels.SupplyPart_ID = " & Me.SupplyPart_ID & ");"
DoCmd.RunSQL SQL
Me.Parent.[subFrmWQryWindows(New)].Form.Requery
End If
End If
End Sub