PC Review


Reply
Thread Tools Rate Thread

Button to delete record on datasheet subform

 
 
Robert
Guest
Posts: n/a
 
      24th May 2008
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





 
Reply With Quote
 
 
 
 
Wayne-I-M
Guest
Posts: n/a
 
      24th May 2008
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


--
Wayne
Manchester, England.



"Robert" wrote:

> 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
>
>
>
>
>
>

 
Reply With Quote
 
 
 
 
Robert
Guest
Posts: n/a
 
      25th May 2008
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?

"Wayne-I-M" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>
> --
> Wayne
> Manchester, England.
>
>
>
> "Robert" wrote:
>
>> 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
>>
>>
>>
>>
>>
>>

>




 
Reply With Quote
 
Wayne-I-M
Guest
Posts: n/a
 
      25th May 2008
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


--
Wayne
Manchester, England.



"Robert" wrote:

> 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?
>
> "Wayne-I-M" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> >
> >
> > --
> > Wayne
> > Manchester, England.
> >
> >
> >
> > "Robert" wrote:
> >
> >> 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
> >>
> >>
> >>
> >>
> >>
> >>

> >

>
>
>
>

 
Reply With Quote
 
Jan Baird
Guest
Posts: n/a
 
      27th May 2008
Jan Baird is out of the country until September 20. Every effort will be
made to respond to messages, but please be patient.

 
Reply With Quote
 
Robert
Guest
Posts: n/a
 
      30th May 2008
What?
"Jan Baird" <(E-Mail Removed)> wrote in message
news:C461B450.12485%(E-Mail Removed)...
> Jan Baird is out of the country until September 20. Every effort will be
> made to respond to messages, but please be patient.
>
>




 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't delete datasheet subform record in Access 2007? WPW07 Microsoft Access Forms 0 6th Mar 2008 08:28 PM
code to delete a record in one subform when a record in a related subform is deleted Helen Microsoft Access Form Coding 3 3rd Apr 2005 10:01 PM
Urgent !!! - Values from Subform - #Error if no records in Subform and Only grabs first subform record Greg Microsoft Access Forms 0 17th Feb 2005 02:12 PM
Click on record in a subform datasheet to open another form displaying info related to that record??? edself Microsoft Access Forms 1 24th Nov 2003 08:28 PM
Click on a record in a subform datasheet to open another form displaying info related to that record??? edself Microsoft Access Forms 2 24th Nov 2003 07:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:13 PM.