ms-accessms-access-2016

"Make Trusted Document" warning doesn't trigger until exit, causing "Can't exit now" error


Y'all, I'm about to go completely insane. I'm a perfectionist and I cannot figure out why the Security Warning: "Do you want to make this file a Trusted Document?" doesn't trigger until I try to close my database, causing a "You can't exit [DB] now" error. The database is located on a Network Share Drive and it is designed to detect whether it's local or not and then prompt the user to save a local copy, open that local copy, and close itself.

The problem is that it throws a very bad looking error when it tries to close. It doesn't matter if I use a Macro or VBA, embedded or standalone, both generate the same error. If I close the form or database manually, the Security Warning ("Do you want to make this a Trusted Document?") finally triggers, but the error isn't generated.

I'm running: Microsoft 365 Apps for enterprise Version 2401 (Build 17231.2090 Click-to-Run)

My Goal

Either trigger the Security Warning on load, or detect the Security Warning and halt execution until it's acted on.

The Error and Warning in Question

What happens next

Impact: Fundamentally, this is a minor error that goes away entirely once users properly move the database to a local drive. However, it is driving me insane because it's so inexplicable and also the first touch on my DB my users will have.

What I've Tried So Far

  1. Embedded Macro in button: "Quit"
  2. VBA function with Application.Quit at the end
  3. VBA function with only Application.Quit inside
  4. DoCmd.SetWarnings
  5. Compact and Repair
  6. Deleting all the new code/forms/macros that I haven't used before
  7. Copy and Pasting everything into a new *.accdb file
  8. Adding "Do Until newApp.CurrentProject.IsTrusted : Sleep 500 : Loop" before Quit
  9. Physically going home and trying a VPN connection
  10. Waiting 15 minutes for the Security Warning to trigger
  11. Running a "do nothing" VBA or Macro (DoEvents and Echo off/on) OnLoad and Button_OnClick

None of these have changed the error.

Database Structure

Forms:
- Warn Not Trusted (default)
- Warn On Network
- Admin Options

Macros:
- AutoExec:
  - If [isTrusted], close "Warn Not Trusted"
  - If vbaDriveType <> "Local", show "Warn On Network"
  - Else, UpdateMainDB, then LaunchMainDB

VBA:
- UpdateMainDB/LaunchMainDB: Checks version, then either updates or launches main DB.
- Utilities: vbaDriveType: If .Path like C:\*, then Local

Limitations

Did I miss something obvious? Am I SOL? Did I stumble upon a genuine bug?

For my steadily dwindling sanity, I beg y'all for help!


Solution

  • Stumbled upon the answer: Using a Macro to open a form as a Dialog suspends execution until the form is closed, regardless of whether there is any further code/macro to execute. See remarks here: https://support.microsoft.com/en-us/office/openform-macro-action-8ece67cc-783c-4b2e-9f33-0e24e8436a05

    Solution: Open the form as Normal, with Modal and Popup set to "Yes".

    I hadn't included that detail in my initial question as I didn't recognize it as important. I may not get my 9 hours back, but maybe someone else can avoid this dumb fate.