0

I have a MS Access project, which was developed in MS Access 97. I successfully converted it to MS Access 2016 (that was a long story tho). Everything looks fine, but I have noticed a very strange behavior.

When user opens the project file in client mode for the first time, a lot of macro errors pop up. This is a normal thing, because user has not yet allowed unsafe content in this file. So, after user has closed all the errors, he presses "Allow unsafe content" button and closes the file. Now user opens the project again and it is not working properly. Some forms are invoked that should'nt be invoked and "Module not found" error pops up. I didn't develop any modules for this program. So, it means that if user opens the file without allowing unsafe content first, the project gets totally messed up and it's impossible to recover unless you replace the file with a fresh copy.

However, if user has a fresh copy of project .accdb file, and the file is located in trusted location, everything works fine. Another way to make project run properly without putting it to trusted location is to open it while holding shift key first and pressing "Allow unsafe content" button. Then user can normally run file with double-click and it works like it should.

So, opening this file without allowing unsafe content first breaks the project. I've also tried to open VBA code of the form, which is invoked by default and the VBA code windows looks frozen. Other forms are working fine. enter image description here

How can I debug this problem?

UPD: It really looks like the problem is caused by attempting to run macros while unsafe content is not enabled.

UPD: I noticed one more thing - if I run the project without allowing unsafe content first, but I don't press "allow content", and just close the program - I'm still able to run it from trusted location. So the corruption happens only after I press "enable content" button. My form has macro with OnClose action attached. But I tried to remove all the macros from this form and it didn't help.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
fakemeta
  • 938
  • 1
  • 8
  • 21
  • You are making a few false assumptions. First of all you database does have modules. The moment a single event in a single form is scripted, a module for that form is generated. Second, and most importantly, you are taking the words "unsafe content" seriously. For MS Access every little bit of VBA code is "unsafe". This is meant to protect from opening a random file you downloaded from the Internet or got in an email. For a file that was developed in house it is not only safe but it is essential to allow VBA to run unhindered. – SunKnight0 Jan 11 '17 at 19:59
  • @SunKnight0 I didn't mean my database has no modules. I meant I didn't develop any of those. And you are right, there's nothing wrong with allowing Access to run unsafe code in this file, and I understand what "unsafe" means. There might be cases when new users on their fresh installed Windows double-click the .accdb file accidentally without allowing unsafe content first, and it breaks my program. In this cases I will have to give them a fresh copy of the project. That's the problem for me. – fakemeta Jan 11 '17 at 20:43
  • @SunKnight0 To be more clear - usually when user runs new .accdb file with macros there will be errors during start up (stuff about unsafe actions in macros etc) and "Enable content" button appears. When user clicks the button, the program restarts without any macro errors and works fine. But in my case the program restarts with corruptions and I can't revert these corruptions. – fakemeta Jan 11 '17 at 20:45
  • That's pretty weird. Is it a single file or does it link to external data? If it does and depending on how the external data is linked, it could explain why it "breaks". If you are on a Windows domain environment you can set access to always run "unsafe" content via group policy. Doesn't explain why it happens but it does bypass the problem. – SunKnight0 Jan 11 '17 at 20:47
  • @SunKnight0 Yes, it's a single file. – fakemeta Jan 11 '17 at 20:48
  • @SunKnight0 Maybe MS Access automatically removes some parts of code it considers unsafe during the start up without unsafe content enabled? – fakemeta Jan 11 '17 at 20:49
  • Sorry was editing. See my group policy suggestion. As to why it breaks, look for any startup macro or code or OnOpen/OnLoad code in the startup form. – SunKnight0 Jan 11 '17 at 20:49
  • I have never seen MS Access permanently remove code. – SunKnight0 Jan 11 '17 at 20:52
  • @SunKnight0 Well, changing group policies is just an another way to bypass this bug. But in my case I really need to fix it to prevent stupid situations. 20 minutes ago a user came and asked for another copy of this program because he moved .accdb to another folder and forgot to add it to trusted location before running. – fakemeta Jan 11 '17 at 20:56
  • Sure but it bypasses it permanently. Anyway without actually looking at the file I can't even begin to guess why it actually breaks. Try disabling the startup form/macro and open it and see if that will break it as well. – SunKnight0 Jan 11 '17 at 21:00
  • @SunKnight0 I updated my question. – fakemeta Jan 11 '17 at 21:00
  • Based on the update it seems your problem is definitely code that runs but not fully (for example your end code runs but your startup code does not). In addition to disabling any macros you would have to also disable any `OnOpen`, `OnCurrent`, `OnLoad` and `OnClose` VBA code (and probably more that I am missing) for any form/subform that may be activated, in order to troubleshoot. – SunKnight0 Jan 11 '17 at 21:03
  • @SunKnight0 Yes, I thinks that's a good idea. I will check it tomorrow and tell you the results. – fakemeta Jan 11 '17 at 21:12
  • @SunKnight0 I removed ALL VBA code from my startup form and it didn't help. But I've found a solution and posted it as an answer. – fakemeta Jan 13 '17 at 19:53

1 Answers1

0

I've ran into some more weird problems and while debugging them found out that there are some MS Office 2000 footprints on the system. I decided to uninstall MS Office, clean Windows registry and install MS Office again. This solved all my problems.

fakemeta
  • 938
  • 1
  • 8
  • 21