delete button deletes the wrong thing


Kathy R.

I have a form/subform (frmAttendance/sfrAttendee) with a delete record
button on the main form. If my cursor is in a field on the subform, the
delete button deletes the record in the subform. I want it to delete
the record on the main form.

Could you please take a look at this code and tell me what I'm doing
wrong? Thanks!

Kathy R.

Private Sub cmdDelete_Click()

On Error GoTo cmdDelete_Click_Err

On Error Resume Next

DoCmd.GoToControl Screen.PreviousControl.Name

If (Not Form.NewRecord) Then
DoCmd.RunCommand acCmdDeleteRecord
End If

If (Form.NewRecord And Not Form.Dirty) Then
End If

If (Form.NewRecord And Form.Dirty) Then
DoCmd.RunCommand acCmdUndo
End If

If (MacroError <> 0) Then
MsgBox MacroError.Description, vbOKOnly, ""
End If

Exit Sub

MsgBox Error$
Resume cmdDelete_Click_Exit

End Sub

Daryl S

Kathy -

Before the first If statement, you want to set the focus to a control in the
main form. Pick a control that can take focus, and put it in the code like


Then try out your code.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question