From: Kathy R. on
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
Err.Clear

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

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

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

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


cmdDelete_Click_Exit:
Exit Sub

cmdDelete_Click_Err:
MsgBox Error$
Resume cmdDelete_Click_Exit

End Sub
From: Daryl S on
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
this:

Me.YourControlName.SetFocus

Then try out your code.
--
Daryl S


"Kathy R." wrote:

> 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
> Err.Clear
>
> If (Not Form.NewRecord) Then
> DoCmd.RunCommand acCmdDeleteRecord
> End If
>
> If (Form.NewRecord And Not Form.Dirty) Then
> Beep
> End If
>
> If (Form.NewRecord And Form.Dirty) Then
> DoCmd.RunCommand acCmdUndo
> End If
>
> If (MacroError <> 0) Then
> Beep
> MsgBox MacroError.Description, vbOKOnly, ""
> End If
>
>
> cmdDelete_Click_Exit:
> Exit Sub
>
> cmdDelete_Click_Err:
> MsgBox Error$
> Resume cmdDelete_Click_Exit
>
> End Sub
> .
>
From: Kathy R. on
Thank you Daryl, that worked great!

Kathy R.

Daryl S wrote:
> 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
> this:
>
> Me.YourControlName.SetFocus
>
> Then try out your code.