Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2004
    Location
    CA
    Posts
    3

    Unanswered: Delete Record on Subform using cmdButton on main form

    I have a form with a subform in datasheet view.

    How can I implement a button on the main form that will delete the selected records on the subform?

  2. #2
    Join Date
    Feb 2004
    Location
    Dorset UK
    Posts
    147
    Is there any record selector on the main form ?

    Or is it just a subform ?

  3. #3
    Join Date
    Mar 2004
    Location
    CA
    Posts
    3
    There are no record selectors in the main form.

    The main form exists to populate the subform. (Which is in datasheet view) On the main form is a combo box and the command button in question. The combo box is populated using the "parents'" names. The combo box, on change, instructs the subform to requery. Requerying the subform populates it with the "child" records of the selection made in the combo box in main.

    The intended function for this form is: After selecting the parent, the user will then make the child selection(s) on the datasheet and click the delete button on the main form.

    If I put the delete button on the toolbar, it can be used to produce the desired effect. However, the toolbars are customized and usage of a toolbar button would break the uniformity of my user interface.

    Thanks for you suggestions...

  4. #4
    Join Date
    Nov 2003
    Posts
    1,487
    The key to this is making sure that you are in fact deleting a record within the subform and not from the parent form, therefore we need to check that you had in fact clicked onto the record to delete within the subform before carrying out the actual delete process.

    You can do this by using the PreviousControl statement and here's how:

    In the On Click event of your parent form Command button, place the following code:
    Code:
    Dim Ctrl As Control  'Must be the 1st line in the event!
    Set Ctrl = Screen.PreviousControl  'Must be the 2nd line in the event!
    If Ctrl.Name = "mySubFormName" Then
       Ctrl.SetFocus
       DoCmd.RunCommand acCmdDeleteRecord
    End If
    If the subform was not the last control which had focus then the Delete process will not be carried out. You can use this method to delete records from any number of SubForms located within your parent form.

    Hope this helps
    Last edited by CyberLynx; 03-11-04 at 01:58.

  5. #5
    Join Date
    Mar 2004
    Location
    CA
    Posts
    3
    It does help thank you. The only glitch is that it only deletes on record, and typically I select 10 or more rows at a time. What can be done to accommodate multiple row deletion?

Posting Permissions

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