Here is how you do it:
- Set up your VBA code as function (not sub).
- Create a macro that runs that function and then closes the database.
- Create a command prompt batch file that runs your MS Access file with
the /x switch (see example below).
- Set up the batch file as a scheduled task on your server or any
computer you want that VBA code to run on. If not a server make sure
it stays on and there is no power saving on network card, no sleep/suspend. Make sure the scheduled task's user has any required privileges.
You can set up a scheduled task to run with admin privileges. Generally if the user set up as the user for the task can run it, then the scheduled task will run as well. It does not have to be the user creating the scheduled task. If necessary create a user account with the required permissions and use that.
Batch file example:
"C:\Program Files\Microsoft Office\Office16\MSACCESS.EXE" "C:\Databases\MyDatabase.accdb" /x Daily
EXIT
This will run Access 2016, 64-bit, open the MyDatabase.accdb file and run the macro named "Daily" .
As an addition: It is possible to do scheduled tasks and use Outlook as a sender. But if you don't need to use Outlook as a sender you can make your life a little easier and use Swithmail
.
If you absolutely need to use Outlook, check this:
https://support.microsoft.com/en-us/help/3189806/a-program-is-trying-to-send-an-e-mail-message-on-your-behalf-warning-i