Cancel a Macro

shrive22

Board Regular
Joined
Jun 10, 2002
Messages
120
I have an exit button that closes my form. on the beforeupdate event have a msgbox asking the users if they want to save the changes. heres the code:
-----------------------------------------------------------

Private Sub Form_BeforeUpdate(Cancel As Integer)
' Confirm with user that this record is to be modified

Dim updRecord As Byte

updRecord = MsgBox("Are you sure you want to update this record", vbOKCancel, "Update Record Confirmation")

If updRecord = vbCancel Then
Dim CTRL As Control
For Each CTRL In Forms!changegroup
Me.Undo
Next CTRL
Cancel = True
End If

End Sub
-------------------------------------------------

when I click cancel i get an error : You cant save this record at this time
then it tells me the action close form failed.

I thought since I have the for loop changeing all of the data values back to what they were would avoid this problem. any ideas ???

thanks
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
I have just tried your code and it runs with out a problem.
The loop does not clear each controll seperatley as the Me in the loop still refers to the form not the controll.

Have you tried adding a breakpoint and stepping through the code to see just what is happening?

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