Reputation: 149
I have a Subform within a Form in Access 03. I need a macro that will delete a row in the subform. I tried the below code but it only deletes the fields in the form.
Private Sub Command104_Click()
On Error GoTo Err_cmdDeleteCustomer_Click
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Exit_cmdDeleteCustomer_Click:
Exit Sub
Err_cmdDeleteCustomer_Click:
MsgBox Err.Description
Resume Exit_cmdDeleteCustomer_Click
End Sub
Upvotes: 1
Views: 1727
Reputation: 91376
You are using Wizard code. It is very bad and has been deprecated for sometime. The newer version is DoCmd.RunCommand. For the subform, it would be easier to run a little sql from a command button, for example:
Dim db As Database
Dim sSQL As String
Set db = CurrentDB
sSQL = "DELETE FROM MyTable WHERE ID =" & Me.MyNumericIDControlName
db.Execute sSQL, dbFailOnError
MsgBox "Deleted " & db.RecordsAffected
Upvotes: 1