Results 1 to 8 of 8
  1. #1
    sprtrmp is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    Greenville, SC
    Posts
    102

    Cancel button

    What is the best way to program a cancel button?



    on my form, I have several controls that the user would fill out about inventory assigned to an employee. most of the controls are combo boxes with a text box for quantity. If the user gets to some point in the process, but decides they made a mistake, I want them to be able to click one button, and have all of the boxes cleared out, and go back to the beginning.

    the way I have it set up now, everything clears, and no record is added to the underlying table, BUT the table also seems to burn an autonumber for the record that was canceled. so, the next valid record added would be the previous record +2. It isn't a huge deal, I know that record number isn't truly important and it only needs to be unique, but for clarity purposes and such, I would just prefer if the numbers were consecutive.

    is there any way to cancel inputting a record and NOT have Access burn off an autonumber?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    you make a 'temp' table for data entry. User fills in THIS table, CANCEL will close the form (no harm no foul)
    the SAVE button runs an append query to the main table, and no autonum is wasted.

  3. #3
    sprtrmp is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    Greenville, SC
    Posts
    102
    what is this sorcery??

    hmm, sounds like an interesting idea.

  4. #4
    NTC is offline VIP
    Windows 7 64bit Access 2013
    Join Date
    Nov 2009
    Posts
    2,392
    press the ESC key.....

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    is there any way to cancel inputting a record and NOT have Access burn off an autonumber?
    Use a custom Autonumber....... a custom Autonumber is one that you control and is only added in the form before update event.

    How to generate a customized AutoNumber? One method --> http://www.baldyweb.com/CustomAutonumber.htm

  6. #6
    sprtrmp is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    Greenville, SC
    Posts
    102
    That's pretty useful, I am going to store that away for future reference.
    I suspect that what I was aiming at in my original post was trying to figure out a way to completely clear a form, and scrap the entire thing. What I have now is a "Cancel" button that sets all of the combo boxes to "Empty", sets the quantity textbox to "0", and puts the focus back on the first combo box. when looking at the related table, I had assumed that my hitting the "Cancel" button resulted in that autonumber being skipped. and it may, but now I see that it really doesn't matter if it skips a number, and the ONLY thing that DOES matter is that the number is unique. I had assumed that it was some kind of flaw in the VBA of my "Cancel" button that was causing it (and I guess it still could be).

    just inexperience... and a slightly anal-retentive nature.

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You might find these useful or informative:

    Use Autonumbers properly
    http://access.mvps.org/access/general/gen0025.htm

    Autonumbers--What they are NOT and What They Are
    http://www.utteraccess.com/wiki/index.php/Autonumbers


  8. #8
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 8 Access 2013
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    For Bound forms:

    Pressing Esc twice is the keyboard shortcut for Undo for a record that has not been saved..

    From VBA code use:

    Code:
    If Me.Dirty then Me.Undo

Please reply to this thread with any new information or opinions.

Similar Threads

  1. InputBox Cancel Button
    By mmaule in forum Access
    Replies: 4
    Last Post: 05-22-2014, 05:56 AM
  2. Cancel Button not working
    By alexandervj in forum Access
    Replies: 16
    Last Post: 02-06-2014, 12:27 PM
  3. Cancel button in Quit Macro
    By ashu.doc in forum Forms
    Replies: 3
    Last Post: 09-19-2012, 04:40 PM
  4. Parameter Value Cancel button
    By Darkladymelz in forum Queries
    Replies: 1
    Last Post: 03-14-2012, 04:27 PM
  5. Cancel button for adding data
    By eliotchs in forum Forms
    Replies: 1
    Last Post: 11-21-2011, 04:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums