Making Delete Button

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

What is the easiest way to make a delete button to delete a record and its
corresponding daughter records?

Thanks
 
What is the easiest way to make a delete button to delete a record and its
corresponding daughter records?

Thanks


Turn on the control wizard, draw a button on the form and follow the
steps.
The wizard button looks like a magic wand.
 
Thanks and that worked great except that when I run the delete the button and
cancel it before it deletes I get a message that says "The DoMenuItem was
cancelled"

Is there a way to get rid of that message?
Thanks
 
The wizard should have generated code in the Click event of the
button. I can't remember everything it puts in but there should be an
On Error Goto...statement - just after that line enter this

DoCmd.SetWarnings False

There should also be something toward the bottom like:
ButtonName_Error_Click:
Exit Sub

Add DoCmd.SetWarnings True between the above lines.

This should eliminate the msgbox. If not let me know and I'll try
something else.
 
The wizard should have generated code in the Click event of the
button. I can't remember everything it puts in but there should be an
On Error Goto...statement - just after that line enter this

DoCmd.SetWarnings False

There should also be something toward the bottom like:
ButtonName_Error_Click:
Exit Sub

Add DoCmd.SetWarnings True between the above lines.

This should eliminate the msgbox. If not let me know and I'll try
something else.


Ignore my last post, I forgot that the cancelation message is an
error, not a warning. Don't use what I last outlined unless you want
to hide the warning message as well.

Instead you'll need to change the error hanlding in that event. It
probably looks similar to

Exit_Command5_Click:
Exit Sub

Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click
End Sub

Change it to look like this.

Err_Command5_Click:
If Err.Number <> 2501 Then MsgBox Err.Description
Resume Exit_Command5_Click
End Sub
 
Here is the code I am not sure I entered you suggestions in the right place

Private Sub Delete_Records_Click()
On Error GoTo Err_Delete_Records_Click
DoCmd.SetWarnings False

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Exit_Delete_Records_Click:
DoCmd.SetWarnings True
Exit Sub

Err_Delete_Records_Click:
MsgBox Err.Description
Resume Exit_Delete_Records_Click

End Sub
 
To address the portion of your question about deleting "daughter" records as
well, you would need to go into Tools, Relationships, and upon creating the
relationship check the Cascade Delete Related Records.

Careful about this one, you could be deleting one record in the main table,
and be deleting thousands of records in the "daughter" table.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top