Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658

    How to NOT save VBA changes

    Let's say some changes were made to forms that one wants to keep.
    Then some changes were made to the VBA code and saved.
    Then some more changes are made to the VBA code, but you realize that replace did a bit more than you wanted, maybe even a few hundred times.


    You want to exit without saving (or doing a mountain of ctrl-z) the recent replace changes, but you don't want to lose the form changes.
    It seems Access VBA editor wants to save those bad replaces no matter what.
    How can this be done? What's the trick?
    Last edited by twgonder; 01-06-2023 at 12:33 PM. Reason: New .accdb

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    From design mode, it asks if you want to save changes before closing the form?
    Simply say no and everything you have done since you last saved it will be ignored.
    If you have already saved it then tough, unless you have some backup routine going to keep timed versions.

    The form and it's code module are inexorably linked, unless you put all the code into lots of separate modules, which is normally more trouble than it is worth for form specific items.
    The other option is to save a version of the form frm_Menu01 and copy and create a new version before each major update, again not really needed in a development environment if you have a good backup routine.

    If you want to be selective about keeping some of the changes but not others I've no idea how, and am not aware of any IDE that is omnipotent enough to work that out for you?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    You can comment out the code lines you don't want to keep (or just delete them).
    The block comment feature is particularly useful in this respect
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  4. #4
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    Quote Originally Posted by Minty View Post
    From design mode, ...
    If you want to be selective about keeping some of the changes but not others I've no idea how, and am not aware of any IDE that is omnipotent enough to work that out for you?
    I think you made the situation more complicated than I intended. Let's suppose it's VBA NOT tied to a form. Between backups.
    You make a lot of changes to a VBA module with replace. Then need that those aren't saved because of a massive replace error. But, you don't want to lose design changes to forms or other modules. You just don't want a new save to happen to that particular VBA module since the last save (a few moments before).
    How?

    Most applications have an "exit" or "close" option that doesn't do a save (see Word, Excel, etc.).
    Or a close under the file tab doesn't save or presents a message box asking if a save might be wanted.
    Click image for larger version. 

Name:	230106Save.jpg 
Views:	20 
Size:	90.3 KB 
ID:	49456

    I don't see that here in the VBA editor. The VBA editor just seems to want to save no matter what, as far as I can see.
    Yeah, I know it's one big .accdb file, but if I can save or not save tables, forms, queries, etc. then the same should be for VBA code, no?
    Last edited by twgonder; 01-06-2023 at 06:12 PM. Reason: added clarification with visual

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    When you go to exit Access it will ask if you want to save that particular module?

    If you are working as you are working then save between modules.

    Alternative you could copy out the code to Notepad or NotePad+, and then replace and then *CHECK* your amendments. If all good, copy and paste it back to the module.?

    Excel does it the same way does it not? It does not ask you to save a sheet at a time, you save the workbook or not, so if you cock up Sheet 2 and go on to amend Sheet1, and then Save, tough luck.

    I created code to save my DB with datetimestamp. Sometimes I would have 5 or 6 created for the same day.

    I really think you would be better off developing your own developing environment with all the features you complain are not available within Access.?
    Then if others feel the same you would make a fortune selling it.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    Quote Originally Posted by Welshgasman View Post
    ...

    Excel does it the same way does it not? It does not ask you to save a sheet at a time, you save the workbook or not, so if you cock up Sheet 2 and go on to amend Sheet1, and then Save, tough luck....
    You missed the whole point, I'm not saying I want to SAVE the messed up "Sheet 2", I want to EXIT/CLOSE without saving. As I showed in the Word example.
    It won't do any good to create my own, which I have in the past, and that's been answered many times over. We're stuck with Windows and Microsoft and the ass-backwards ways they've created. For example, as seen in the mentioned Office products, have you in any other software been able to ctrl-z (or its undo equivalent) been able to undo changes made before a save?

    It's easy to plan with backups, exports and version control for the big changes, it's those annoying little ooops that would be nice to back out of easily, in the same work environment (VBA Editor) without having to do dozens or hundreds of undos ctrl-z and maybe have those undo changes before the last save.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    I cannot see how I am missing the point TBH.

    When you amend modules and do not issue a Ctrl + S when you are in one, then when you exit Access it will prompt you if you want to save the changes, and will list all the modules amended. That includes Forms etc
    You can then choose NOT to save a particular module(s).
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    Quote Originally Posted by Welshgasman View Post
    When you go to exit Access it will ask if you want to save that particular module?
    True enough, Access does ask outside the VBA editor if you want to save.
    Here is an example:

    Attachment 49460

    And you would think that un-blue-highlighting the things you don't want to save and then answering yes would avoid saving those errors that were made.
    You would expect that only the highlighted objects would be saved, yes? (otherwise, what's the point of selecting?)
    But my testing shows the Access goes ahead and saves the un-highlighted objects anyways.
    At least in my ver. 2001 of Access

    Isn't Microsoft the company that claims to be enhancing the user experience?
    Wasn't that the great excuse for their uncompetitive marketplace antics?
    So, now that they've wiped out the competition, maybe they could listen a little more?
    I have yet to find an easy way to report bugs or suggestions (like my OQ) to their development team.

  9. #9
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    Quote Originally Posted by Welshgasman View Post
    ...
    You can then choose NOT to save a particular module(s).
    We posted over the top of each other.
    My testing says this isn't true. But, maybe I'm doing it wrong.
    How do you not save the changes?

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    No, if I unhighlight an entry, that does NOT get saved.
    I just checked now. never had to in the past.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  11. #11
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    Quote Originally Posted by Welshgasman View Post
    No, if I unhighlight an entry, that does NOT get saved.
    I just checked now. never had to in the past.
    Well, I've just tested it a half-dozen times (just to make sure I'm doing the correct objects which have similar names)
    in my Access 2021, and it saves the VBA module with the changes even if I unhighlight it and then press yes.
    I even tried reversing the highlighting to see if I had it backwards.

    It won't save a form design, if it's not highlighted, but for me it always saves a VBA module.
    Did you test this scenario?

  12. #12
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    If it's the only module listed press no?
    It definitely works with multiple modules listed.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  13. #13
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    Here's a video showing it SAVING the changes (even when told NOT TO SAVE):
    https://1drv.ms/v/s!AmMsCrz5d72TgZJ5...b5AkA?e=eUAFW1

  14. #14
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Ok, I will accept it does not work for you, but does pretty much for everyone else.
    I use 2007, so you would need to find someone with the same version/setup as you and see if that happens to them?

    All I can say, is I just tested as you did, but I used code subs, one from a form and one from a module. I chose to save the form version and not the module and it did as requested.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  15. #15
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    Quote Originally Posted by Welshgasman View Post
    Ok, I will accept it does not work for you, but does pretty much for everyone else.
    I use 2007, so you would need to find someone with the same version/setup as you and see if that happens to them?

    All I can say, is I just tested as you did, but I used code subs, one from a form and one from a module. I chose to save the form version and not the module and it did as requested.
    Is that everyone else that uses a modern version of Access? Mine is a "special" version of Access 2021?
    Since we're giving lots of advice here on what people should or shouldn't do, not just in development, but in what tool to use or to develop for themselves,
    I'll say, don't upgrade to a version of Access that is 14 years newer than the one you use!
    Everyone, go back to Access 2007 (mainstream end date in 2012).
    Really?!!!

    Final observation: Some of the forum members are telling me to quit thinking about my old designs (which I'm porting to Access, so I have to think about them) and get with the times of a modern RAD (Access) and learn how to use the tool?!!! Another classic example in this thread.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 11-13-2017, 08:51 AM
  2. Replies: 5
    Last Post: 02-03-2014, 03:06 AM
  3. Replies: 15
    Last Post: 01-28-2014, 12:20 PM
  4. Replies: 3
    Last Post: 10-08-2012, 08:40 AM
  5. Replies: 9
    Last Post: 01-20-2011, 02:22 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