Setting focus on a control in a subform from the main form is a two step
process: first set the focus on the subform control then set the focus on the
control. This rule applies in your case because Subfrm2 is a control on Subfrm1
and FrmA is the main form. (Assuming that Subfrm1 and Subfrm2 are both names of
subforms and also the names of the subform controls that hold the subforms)
Also, once you set focus on a subform control, executing DoCmd.RunCommand
acCmdDeleteRecord will delete the current record in the subform. So you need the
following code:
Public Function DeleteRecord()
Forms!frmA!Subfrm1.SetFocus
Forms!frmA!Subfrm1.Form!Subfrm2.SetFocus
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
End Function
--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com www.pcdatasheet.com
"Mark B" <remove_from
_h*********************@ihug.co.nz> wrote in message
news:bq**********@lust.ihug.co.nz...
I have a form with a subform (normal) that itself has a subform (datasheet).
I can't get a delete command button to work with the following code. It says
"delete not available now". Any suggestions?
'************************************************* ****************
Public Function DeleteRecord()
Dim frm As Form, subfrm As Form
Set frm = Forms!frmA!Subfrm1.Form
Set subfrm = frm!Subfrm2.Form
frm!Subfrm2.SetFocus
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
End Function
'************************************************* ****************