Cancel button in modal window

Solved
ButteDuLac Posted messages 534 Status Member -  
ButteDuLac Posted messages 534 Status Member -
Hello,

In Access 2010, I created a modal window that serves to add a record to a list table (linked to a field in a parent table).

There is an OK button and a Cancel button. These two buttons are automatically inserted by Access.

The Cancel button should, in theory, cancel the newly created record, but it doesn't work. Whether I click OK or Cancel, the result is the same; the record has been saved.

How can I resolve this very annoying situation?

Thanks!

2 answers

  1. le meruvien Posted messages 1414 Status Member 44
     
    Hello,
    Apparently, you don't know VBA and coding?
    So, from the standard form, you can't do anything; you must switch it to design mode, and there, select your cancel button, and in the properties window, check if the action "on click" is linked to a procedure! In that procedure, you should see:
    Forms![form name].Undo
    or
    DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
    0
    1. ButteDuLac Posted messages 534 Status Member 41
       
      That's exactly the problem. If I could SEE the code, I could check it. But I only see the Macro window (macro generator) and I can't find how to display the code.
      If I select the button and click on View Code, the form's code appears (all I see is Option Compare Database)
      If I click on the generator button (...) to the right of the "On Click" box in the button's property window, I get the macro associated with the button, but all I see as operations is "Close Window" and "Save: with confirmation," as described in my question. I've tried changing it to "Save: no," but it doesn't do anything.
      I would really like to be able to check the codes and change them if needed, but in this specific situation, I can't access them, I don't understand how to do it... I even tried right-clicking the button and "Create Event Code," but I also end up in the macro generator window.
      0
    2. le meruvien Posted messages 1414 Status Member 44
       
      I'm sorry, unfortunately I don't know Access 2010, I've stuck to 2003
      Roger
      0
    3. ButteDuLac Posted messages 534 Status Member 41
       
      Ah, OK! Thanks for trying.
      In the end, I completely deleted the macro, then replaced it with an Undo recording macro, ending with CloseWindow, and now it works. At first, I thought it didn't, but I just hadn't entered any data yet. After a test in a test copy of my database, it works!!!
      0
    4. ButteDuLac Posted messages 534 Status Member 41
       
      Oops!
      There is a small bug. If I open the window and don't enter any record, if I click on Cancel, a bug occurs and Access asks me if I want to stop the macro.
      For me, there is no problem, but for the user who has no programming knowledge at all (read worse than me!), it will be gibberish!
      There is the X button to close the window, but people often have the reflex to click OK or Cancel.
      Whether in code or otherwise, is there a way to fix this?
      0
    5. castours > ButteDuLac Posted messages 534 Status Member
       
      Hello
      To see the button code, try switching to creation mode, then go to your button, click on it, then properties, then events. You should have the procedure on click.
      0
  2. Tessel75
     
    Hello,
    I realized quite some time ago that recent versions of Access no longer allowed you to "see" the macros associated with pre-built buttons.
    To get around this difficulty, the only way I know is not to use this type of button, but to put generic buttons and add custom macros onto them. The advantage, in addition, is that it is then possible to convert the macros into VBA code, thus gradually learning how to write code directly.
    0
    1. ButteDuLac Posted messages 534 Status Member 41
       
      Aaaah! That's what I did. Well, it doesn't allow me to close the window, but at least if I click on my new "Cancel Recording" button ;) without having previously entered any data, Access advises me that the action Canceling a record is not available at the moment, but it doesn't ask me to stop the macro. I think anyone will understand that! It's great!!! Thank you for guiding me towards the self-construction of my button, I just needed a little confidence!!! :D
      0