Reputation: 886
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
Upvotes: 6
Views: 25945
Reputation: 622
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'
Upvotes: 1
Reputation: 21647
You need to "trust" the location of the database.
.
On the File tab, click Options.
In the Access Options dialog box, on the left, click Trust Center.
On the right, under Microsoft Office Access Trust Center, click Trust Center Settings.
In the left pane of the Trust Center dialog box, click Trusted Locations.
To add a network location, in the right pane, select the Allow Trusted Locations on my network check box.
Click Add new location.
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.
To specify that subfolders of the new trusted locations should also be trusted, select the Subfolders of this location are also trusted check box.
Optionally, in the Description box, type a description for the trusted location.
(Source)
Upvotes: 8