Macro Error 2001 Autoexec Access Macro
Asked Answered
M

2

6

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
Monochord answered 23/11, 2017 at 14:21 Comment(1)
Version is Access 2016Monochord
I
8

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)

Inextirpable answered 23/11, 2017 at 14:35 Comment(1)
Note that you can use CurrentProject.IsTrusted in an If block to check if the project is trusted, and throw descriptive errors if it's not. This needs to be all inside the macro before any unsafe actions, since VBA won't run if the project is not trusted (e.g. If Not CurrentProject.IsTrusted Then MessageBox). This also allows you to put all other code in the Else section, to avoid triggering the error.Kagoshima
B
1

Also note; there is an embedded feature of the product to open an initial form so that no auto exec is needed. Look in 'Options' 'Current Database'

Bagworm answered 29/11, 2017 at 21:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.