I have a main form with a datasheet subform on it. Records can be deleted
from the subform by selecting the record and then clicking on the delete
icon on the toolbar. But I want a custom delete button. And you can't put
a button on a datasheet. So if I put a button on the main form, what code
do I use to delete the selected record(s) on the datasheet subform? The
following when placed in the button's on click event do not work:
DoCmd.RunCommand acCmdDeleteRecord
and
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Robert
Wayne-I-M - 24 May 2008 20:25 GMT
Private Sub MAINFORMNAME_Click()
Dim rs As DAO.Recordset
With Me.DATASHEETFORMNAME.Form
Set rs = .RecordsetClone
rs.Bookmark = .Bookmark
rs.Delete
Set rs = Nothing
End With
End Sub
Change MAINFORMNAME and DATASHEETFORMNAME

Signature
Wayne
Manchester, England.
> I have a main form with a datasheet subform on it. Records can be deleted
> from the subform by selecting the record and then clicking on the delete
[quoted text clipped - 11 lines]
>
>
Robert - 25 May 2008 02:22 GMT
Thank you. It works but it will not delete mulitple records like the icon.
Is there any way to make it delete more than 1 record?
> Private Sub MAINFORMNAME_Click()
> Dim rs As DAO.Recordset
[quoted text clipped - 24 lines]
>>
>> Robert
Wayne-I-M - 25 May 2008 08:17 GMT
Hi Robert
In the subform
I would look into OnClick of the form add the ID to a delete query
On the main form
Use the button to run the query
Then requery the subform
Note
I would put a checker on this.
On click - are you sure you want to delete the selected records -
No = Do nothing
Yes = run the query
Sorry don't have time to do this for you this morning (it's a public holiday
in the UK for the next 2 days - so taking the kids to the beach).
It not difficult so you should be OK - or if you have problems - post back
and someone else will jump in with the answering method

Signature
Wayne
Manchester, England.
> Thank you. It works but it will not delete mulitple records like the icon.
> Is there any way to make it delete more than 1 record?
[quoted text clipped - 27 lines]
> >>
> >> Robert
Jan Baird - 27 May 2008 20:51 GMT
Jan Baird is out of the country until September 20. Every effort will be
made to respond to messages, but please be patient.
Robert - 30 May 2008 00:34 GMT
What?
> Jan Baird is out of the country until September 20. Every effort will be
> made to respond to messages, but please be patient.