The Command or action 'Undo" isnt't available now.

TDC21

Board Regular
Joined
Mar 31, 2017
Messages
97
I have a Form were I converted a a field to a combo box and added the selectable values I want to be available. I also wanted to add a user confirmation to any edits for this field. My VBA is very basic, but I found some code online, I am running a BeforeUpdate macro with the following code,

Private Sub ACTIVE_FLAG_BeforeUpdate(Cancel As Integer)


If MsgBox("Changes have been made to this record." _
& vbCrLf & vbCrLf & "Do you want to save these changes?" _
, vbYesNo, "Changes Made...") = vbYes Then
DoCmd.Save
Else
DoCmd.RunCommand acCmdUndo
End If


End Sub

The prompt and yes no confirmation are working fine when the data is changed, the save cmd is working fine when "yes" is selected, but when "No" is selected I receive

Run-Time error '20146'
The command or action 'Undo' isnt available now?

Any thoughts on what I might have wrong and how it can be fixed?
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Think I got it, this seems to be working

Private Sub WEB_URL_BeforeUpdate(Cancel As Integer)


'Provide the user with the option to save/undo
'changes made to the record in the form


If MsgBox("Changes have been made to this record." _
& vbCrLf & vbCrLf & "Do you want to save these changes?" _
, vbYesNo, "Changes Made...") = vbYes Then
DoCmd.Save
Else
Me.Undo
End If


End Sub
 
Upvote 0
So with the last edit the actual save prompts seem to be working but now it is doing something a little strange and seemingly random. I have 2 fields with essentially the same macro, I edit data and select yes save and no dont save. It seems like about 2/3 of the time, disregarding which field is used or which option is selected, my main form will remove the selected company data and generate a blank form. The associated subform data will remain without change. If I refresh the search the company will repopulate with the edits saved or with the original value depending on the prompt selection. Everything is working but I dont know why a new blank form is being generated?

Any thought?
 
Upvote 0
Looks to me like your intent is to undo the control change, but you're applying the Undo across the whole form, not just the control. Me refers to the form (or report in those cases). I would have invoked the Cancel method seeing as how it's part of this event's structure, but that's out of habit. Your way might work if you use

Me.WEB_URL.Undo
or

Else
Cancel = True
End If
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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