Macro Error 2001 Autoexec Access Macro

bd5*_*528 5 ms-access vba

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
Run Code Online (Sandbox Code Playgroud)

ash*_*awg 8

您需要“信任”数据库的位置。

.

指定受信任的位置(Access 2013 和 2016)

  1. 在文件选项卡上,单击选项。

  2. 在“访问选项”对话框的左侧,单击“信任中心”。

  3. 在右侧的 Microsoft Office 访问信任中心下,单击信任中心设置。

  4. 在“信任中心”对话框的左窗格中,单击“受信任的位置”。

  5. 要添加网络位置,请在右窗格中选中“允许我的网络上的可信位置”复选框。

  6. 单击添加新位置。

  7. 在 Microsoft Office 受信任位置对话框中,使用以下方法之一:

    • 在路径框中,键入要添加的位置的完整路径。

    • 单击浏览以浏览到该位置。

  8. 要指定新受信任位置的子文件夹也应受信任,请选中该位置的子文件夹也受信任复选框。

  9. 或者,在“说明”框中,键入受信任位置的说明。

来源