macro triggering another macro

shrive22

Board Regular
Joined
Jun 10, 2002
Messages
120
I have a macro which has several actions inside it and one of the actions triggers another macro I have assigned to the ondelete property of a form. I get an error from the first macro when I cancel the deletion of the record is there any way to put a condition to capture if the cancel delete button has been selected so that I can cancel the first macro(the one im getting errors on)???

thanks for teh help
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
There are a couple of ways to do it but if you post the code, we will have a better idea of what you are after.

Use the VB HTML Maker (link at the bottom of this board)

HTH

Denis
 
Upvote 0
If you are actualy using Macro's rather than code you can convert the marcos to code using File>Save As/Export and the select "Save as Visual Basic Module".

HTH

Peter
 
Upvote 0
this is the code that is executed when i click the delete record button

'------------------------------------------------------------
' DeleteGroup1
'
'------------------------------------------------------------
Function DeleteGroup1()
On Error GoTo DeleteGroup1_Err

DoCmd.OpenForm "ChangeGroup", acNormal, "", "[group]=[Forms]![Groups]![group]", , acNormal
DoCmd.Close acForm, "Groups"
Call Setwarningoff
DoCmd.RunCommand acCmdDeleteRecord
Call Setwarningon
DoCmd.Close acForm, "ChangeGroup"


DeleteGroup1_Exit:
Exit Function

DeleteGroup1_Err:
MsgBox Error$
Resume DeleteGroup1_Exit

End Function


then when the this is the code that is executed wehn the ondelete event is triggered

'------------------------------------------------------------
' ConfirmDelete
'
'------------------------------------------------------------
Function ConfirmDelete()
On Error GoTo ConfirmDelete_Err

If (MsgBox("Do you want to delete this record?", 273, "Confirm Delete") <> 1) Then
DoCmd.CancelEvent
Exit Function
End If
SendKeys "{Enter}", False


ConfirmDelete_Exit:
Exit Function

ConfirmDelete_Err:
MsgBox Error$
Resume ConfirmDelete_Exit

End Function



thanks
 
Upvote 0
I am not sure why you are running code in the OnDelete event for, If you want to double check that they really want to delete the record do it before calling the delete group function.( which is really a Sub as it does not return any information!)

HTH

Peter
 
Upvote 0
ok so if I run the confirmdelete macro before the deletegroup macro then how do I capture teh cancel button and then cancel the deletion of the record?
 
Upvote 0
I would add it to the DeleteGroup1 Function, that way if they don’t confirm you will not even try to delete the group.


Function DeleteGroup1()
On Error GoTo DeleteGroup1_Err
If (MsgBox("Do you want to delete this record?", 273, "Confirm Delete") <> 1) Then
Exit Sub
End If
DoCmd.OpenForm "ChangeGroup", acNormal, "", "[group]=[Forms]![Groups]![group]", , acNormal
DoCmd.Close acForm, "Groups"
DoCmd.setwarning False
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
DoCmd.Close acForm, "ChangeGroup"


DeleteGroup1_Exit:
Exit Function

DeleteGroup1_Err:
MsgBox Error$
Resume DeleteGroup1_Exit

End Function


HTH

Peter
 
Upvote 0

Forum statistics

Threads
1,221,558
Messages
6,160,484
Members
451,651
Latest member
Penapensil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top