Button to delete record on datasheet subform

Discussion in 'Microsoft Access Form Coding' started by Robert, May 24, 2008.

  1. Robert

    Robert Guest

    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
     
    Robert, May 24, 2008
    #1
    1. Advertisements

  2. Robert

    Wayne-I-M Guest

    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
    >
    >
    >
    >
    >
    >
     
    Wayne-I-M, May 24, 2008
    #2
    1. Advertisements

  3. Robert

    Robert Guest

    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" <> wrote in message
    news:...
    > 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
    >>
    >>
    >>
    >>
    >>
    >>

    >
     
    Robert, May 25, 2008
    #3
  4. Robert

    Wayne-I-M Guest

    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" <> wrote in message
    > news:...
    > > 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
    > >>
    > >>
    > >>
    > >>
    > >>
    > >>

    > >

    >
    >
    >
    >
     
    Wayne-I-M, May 25, 2008
    #4
  5. Robert

    Jan Baird Guest

    Jan Baird is out of the country until September 20. Every effort will be
    made to respond to messages, but please be patient.
     
    Jan Baird, May 27, 2008
    #5
  6. Robert

    Robert Guest

    What?
    "Jan Baird" <> wrote in message
    news:C461B450.12485%...
    > Jan Baird is out of the country until September 20. Every effort will be
    > made to respond to messages, but please be patient.
    >
    >
     
    Robert, May 30, 2008
    #6
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jonathan

    highlight subform datasheet form record

    jonathan, Aug 27, 2003, in forum: Microsoft Access Form Coding
    Replies:
    0
    Views:
    252
    jonathan
    Aug 27, 2003
  2. Helen
    Replies:
    3
    Views:
    357
    Helen
    Apr 3, 2005
  3. Guest
    Replies:
    5
    Views:
    441
    Duane Hookom
    Apr 20, 2006
  4. Replies:
    4
    Views:
    1,382
    Marshall Barton
    Feb 22, 2007
  5. mewins

    Attaching subform(Datasheet) to a subform(Single Form)

    mewins, Jun 29, 2009, in forum: Microsoft Access Form Coding
    Replies:
    1
    Views:
    303
    Jeff Boyce
    Jun 29, 2009
Loading...

Share This Page