Results 1 to 12 of 12
  1. #1
    2 Star Lounger
    Join Date
    Oct 2004
    Location
    Evansville, Indiana, USA
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Delete Record in Subform (2000)

    Is there a way to delete a record in a subform by pressing a button on the main form? Right now when I try this, nothing happens. I am assuming because the focus is no longer in the record in the subform. Is there a way around this?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Delete Record in Subform (2000)

    You could make the button set focus to the subform, then delete a record:

    Private Sub cmdDeleteFromSubForm_Click()
    Me.NameOfSubformControl.SetFocus
    RunCommand acCmdDeleteRecord
    End Sub

    Substitute the appropriate names.

  3. #3
    2 Star Lounger
    Join Date
    Oct 2004
    Location
    Evansville, Indiana, USA
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete Record in Subform (2000)

    Here is the error message I get:

    Compiler error:
    Method of Data Member not found.

    Here is the code:
    Private Sub btnDelete_Click()
    Me.frmentrysub.SetFocus
    RunCommand acCmdDeleteRecord
    End Sub

    the subform is frmentrysub
    the button is called btnDelete

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Delete Record in Subform (2000)

    The line <code>Me.frmentrysub.SetFocus</code> sets the focus to the subform control on the parent form, not to the subform itself, so there is no current record and you can't use the command to delete it. Try this instead to set the focus to the subform object in the control:

    <code>Me.frmentrysub.Form.SetFocus</code>
    Charlotte

  5. #5
    2 Star Lounger
    Join Date
    Oct 2004
    Location
    Evansville, Indiana, USA
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete Record in Subform (2000)

    Charlotte
    I substituted the line you posted and I still get the same error message.
    Any more suggestions?

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Delete Record in Subform (2000)

    Try this:

    <code>Me.frmentrysub.Form.SetFocus
    Me.frmentrysub.Form!MyTextBox.SetFocus</code>

    Where MyTextBox represents the real name of a control in the subform and bound to the underlying recordset. Substitute the appropriate control name and that will put the focus back on the current record and you should then be able to delete it.
    Charlotte

  7. #7
    2 Star Lounger
    Join Date
    Oct 2004
    Location
    Evansville, Indiana, USA
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete Record in Subform (2000)

    I still get the same error message from both lines:
    Me.frmentrysub.Form.SetFocus
    Me.frmentrysub.Form!cmbJob.SetFocus

    The compiler highlights .frmentrysub and says:
    Method or data member not found

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Delete Record in Subform (2000)

    Is frmentrysub the name of the subform control or merely the name of the subform object? When you refer to the control, you must use the name of the control, which could be something entirely different from the name of the subform. The subform control is like a window containing the subform object, and Access makes a distinction between the two.
    Charlotte

  9. #9
    2 Star Lounger
    Join Date
    Oct 2004
    Location
    Evansville, Indiana, USA
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete Record in Subform (2000)

    Charlotte,
    You are correct. I assumed it was the also the name of the subform control, however it wasn't. When I put the correct control name in there,
    me.child808.setfocus works fine.
    Thanks for all your help, it is greatly appreciated.

  10. #10
    2 Star Lounger
    Join Date
    Oct 2004
    Location
    Evansville, Indiana, USA
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete Record in Subform (2000)

    Is there a way to turn off the message that pops up saying you are about to delete one record....?
    I want to create my own message. I know how to create my own, I just don't know how to turn the access message off.

    I know there is a setwarnings command, but is this a bad idea to do?

  11. #11
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Delete Record in Subform (2000)

    You can turn off setwarnings just before you delete the record and turn it on again afterwards safely, but then you need to use one of the form events to confirm that they really want to delete the record. Another way of doing it is to change the way you delete the record. Some constructions in code suppress that message automatically. You would have to post the code you are trying to use in order to get specific suggestions on how to handle it in your case.
    Charlotte

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Delete Record in Subform (2000)

    You could replace the line

    RunCommand acCmdDeleteRecord

    with

    DoCmd.SetWarnings False
    On Error Resume Next
    RunCommand acCmdDeleteRecord
    DoCmd.SetWarnings True

    The DoCmd.SetWarnings instructions turn the warnings off, then on again. The On Error Resume Next suppresses other error messages (you'll get a "no current record" error if you delete the last record). It would also be possible to create an error handler that reacts to specific errors.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •