How do I fix my code so I don't receive an error when opening a backup file that was created automatically?

48 Views Asked by At

When I open the backup file created from the code, I get this message:

If ‘AutoExec’ is a new macro or macro group, make sure you have saved it and that you have typed its name correctly.

The code is a module that runs in the OnLoad event of the Navigation Form that opens automatically when opening the database. The Navigation Pane is empty.

This doesn't happen with ALL the backups. Our server creates backups, but I do not have access to them and our IT is off-site and not always available to restore.

The backup is for front end only, which I work on daily as this database is still in the building phase.

Public Function CreateBackup() As Boolean
    Dim Source As String
    Dim Target As String
    Dim objFso As Object
    Dim Path As String

Source = CurrentDb.Name
'Path = CurrentProject.Path
Path = "P:\Angel\AngelNet Backups\"
Target = Path & "\BackupDB_" & Format(Now(), "mm-dd-yyyy") & ".accdb"

Set objFso = CreateObject("Scripting.FileSystemObject")
Call objFso.CopyFile(Source, Target, True)

End Function
1

There are 1 best solutions below

1
Mathias Z On

This i got from the microsoft website :

You can use an AutoExec macro to test whether a database is trusted when you open the database. Additionally, the macro can open a form that displays a customized message to users if the database is not trusted. This message lets users know that the database must be enabled or trusted for the code to run successfully

https://learn.microsoft.com/en-us/office/troubleshoot/access/error-running-macro

So, could you take a look and check if the macro is called somewhere ? Is the file trusted ? Sometimes a header appears asking you to enable the content of the access database. If you go to starts => options => TrustCentrum. Here you can add a trusted network folder or drive. From then of the file is trusted and the message will normaly no long appear.