Reputation: 1
I have a form called Serch form which contains a subform called projects_subform and the subform is linked to a table called Projects.
Now I want to delete a record from the subform which will in effect delete the same record from the table. Please find below my code for the delete operation.
https://i.sstatic.net/0j699.jpg
Upvotes: 0
Views: 900
Reputation: 511
If the record source (underlying table or query) is of type Dynaset and Allow Deletions property is "Yes", you can delete records on the form by selecting a record and clicking the Delete key on your keyboard (Form Properties).
Alternatively, you can select a record and click Delete in the Home menu bar at the top of the application (Home bar).
Upvotes: 0
Reputation: 55806
You could use the RecordsetClone:
Private Sub cmdDelete_Click()
Dim rs As DAO.Recordset
Msg = "You are about to delete this record."
Style = vbOKCancel + vbQuestion + vbDefaultButton2
Title = "Continue?"
Response = MsgBox(Msg, Style, Title)
If Response = vbOK Then
Set rs = Me.Projects_subform.Form.RecordsetClone
rs.FindFirst "Bookmark = Me.Projects_subform.Form.Bookmark
rs.Delete
Else
MsgBox "No record deleted", vbOKOnly, "No changes made"
End If
End Sub
Upvotes: 1