replace the --> SendKeys "{esc}" MS Access Form control

Question
What can I use (Access 2010) to replace the -->      SendKeys "{esc}"   on the below code.

Why
I have many combo boxes on forms where if a user picks certain values it will change the form considerably.  So if they pick one of these values I warn them and give them the ability to Cancel their picking .
In the past the below code worked great to    Cancel the field update    -and-    put the value back to what it was prior to them picking the new Value

Answers that won't let me solve my problem
1) Why do you want to get rid of -->    SendKeys "{esc}"
2) You can teach the user to hit esc once and that will solve the problem



Code --> Before Update
....
If intResponse = vbCancel Then GoTo BadEnd
.....
.....
BadEnd:
    DoCmd.CancelEvent
    SendKeys "{esc}"
    GoTo ProcedureDone


----
Thanks in advance for any help.
LJG
LVL 2
LJGAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Anders Ebro (Microsoft MVP)Microsoft DeveloperCommented:
If this is run from the beforeUpdate event, then I would use ControlName.Cancel. If I recall correctly, you might need to cancel the update first, so:
Cancel=true
Me.ControlName.Cancel

Open in new window

0
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
As Ander's said, in the BeforeUpdate, just cancel the event.

You can also use Me.Undo in many places to revert things back.   First undo will undo the control, second will undo the entire form (just like hitting the esc key).

Jim.
0
LJGAuthor Commented:
Anders & Jim - thanks so much for looking at my problem - However your solutions do not solve my problem.

DoCmd.CancelEvent --> Cancels the update of the field, however it leaves the value the user picked - Just doesn't let you out of the control unless you hit esc

Me.Undo           --> Me.Undo ONCE undoes the everything you changed on the form - not just the field you are on            
Cancel=true       --> Same as DoCmd.CancelEvent (see above DoCmd.CancelEvent comment)

Me.ControlName.Cancel --> errors out
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
<<Me.Undo           --> Me.Undo ONCE undoes the everything you changed on the form - not just the field you are on    >>

 In the BeforeUpdate, the control has not been updated yet, so yes it will un-do the form as there is no control to un-do.

 which method you use depends on where/when you want the un-do to occur.

Jim.
0
LJGAuthor Commented:
Jim
So is there anything I can use to replace the -->      SendKeys "{esc}"   on the below code to put the combo value back to where it was prior to the user picking a new value?     --->BeforeUpdate


Code --> Before Update
....
If intResponse = vbCancel Then GoTo BadEnd
.....
.....
BadEnd:
    DoCmd.CancelEvent
    SendKeys "{esc}"
    GoTo ProcedureDone
0
Anders Ebro (Microsoft MVP)Microsoft DeveloperCommented:
I had an error in my original post. It should have read:
Cancel=true
Me.ControlName.Undo

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LJGAuthor Commented:
Thanks Anders - Perfect answer

If someone is looking at this,  Anders has the answer, however you might want to add the below.

Form Declarations ---------------------------------------------
    Dim Dirty_YN as boolean
      
On Enter (of control) -----------------------
'Has the record been changed in some other field?
    Dirty_YN = Me.Dirty
'----      
      
On BeforeUpdate(of control) -------------------------------------------

       Cancel=true
       Me.ControlName.Undo
      
        If Dirty_YN = False Then
            Me.Undo
      End If
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.