Search code examples
ms-accessvba

Macro Error 2001 Autoexec Access Macro


I have a Autoexec macro setup on a Access 2016 database to determine which form to open based on Environ("USERNAME").

When I open the database I get a macro Error 2001. If I click Stop All Macros, I can continue using the database without issue, until I change the filename, then the issue happens again.

Are there any options to prevent this error from occurring?

The code being called is

LUser = LCase(Environ("USERNAME")) 'Get current username

DoCmd.OpenForm "frmDash", acNormal, , , , acWindowNormal

If IsNull(DLookup("[sysname]", "tblaccmannew", "sysname=" & "'" & LUser & "'")) Then
    DoCmd.OpenForm "frmSearch", acNormal, , , , acWindowNormal
    Forms!frmDash.Visible = False
End If

Solution

  • You need to "trust" the location of the database.

    .

    Specify a trusted location (Access 2013 & 2016)

    1. On the File tab, click Options.

    2. In the Access Options dialog box, on the left, click Trust Center.

    3. On the right, under Microsoft Office Access Trust Center, click Trust Center Settings.

    4. In the left pane of the Trust Center dialog box, click Trusted Locations.

    5. To add a network location, in the right pane, select the Allow Trusted Locations on my network check box.

    6. Click Add new location.

    7. In the Microsoft Office Trusted Location dialog box, use one of the following methods:

      • In the Path box, type the full path of the location that you want to add.

      • Click Browse to browse to the location.

    8. To specify that subfolders of the new trusted locations should also be trusted, select the Subfolders of this location are also trusted check box.

    9. Optionally, in the Description box, type a description for the trusted location.

    (Source)