Solved

Dirty, undo, or sendkeys "{esc}{sec}"

Posted on 2015-02-05
5
157 Views
Last Modified: 2015-02-05
Hi Experts,
I have a question about the code in a Cancel button on a form.  What is the best way to do in a Cancel Button.  should use: (what ever user(s) updated or enter anything on the form, if they click "Cancel" then anything the user just enter will not save and what ever data on the form before user update will still stay there)
a).  If me.dirty = true then
         me.undo
      end if
      docmd.close

b).  if me.dirty then
         me.undo
     end if
     docmd.close

c). me.undo
     docmd.close

d). sendkeys "{esc}{esc}"   -- this seems not working, may be I did it wrong
     docmd.close

Thanks,
0
Comment
Question by:urjudo
5 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 167 total points
ID: 40591167
I'd use (a) or (b). That should undo any changes to the form where the code is running.
0
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 167 total points
ID: 40591169
just use

me.undo
docmd.close acform, me.name
0
 

Author Comment

by:urjudo
ID: 40591209
are a), b) and c) will do the same thing?
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40591245
yes
0
 
LVL 29

Assisted Solution

by:IrogSinta
IrogSinta earned 166 total points
ID: 40591277
There may be nuances behind the scenes on the handling of these codes but in the end a, b, and c will do pretty much the same. This may just come down to user preference.  Me personally, I would do this:

If Me.Dirty Then Me.Undo
DoCmd.Close
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now