logo
search
Others

How to Automatically Close an Access Database After Emailing a Report

Maira MehtabMaira Mehtab Sep 21, 2026 869 views

Question details

The user needs a way to automatically close a Microsoft Access database after a scheduled task emails a report, while retaining the flexibility to keep the database open under certain conditions.

Product
Microsoft Access
Device & OS
Windows
Scenario
Automating report distribution using Windows Task Scheduler and Microsoft Access.
Observed behavior
The user wants to dynamically control whether the database application terminates or stays open after completing an automated email task.
Before you start

Ensure you have administrative access to Windows Task Scheduler and basic familiarity with Microsoft Access VBA (Visual Basic for Applications) or macro builder.

Solution 1Recommended

Pass Command-Line Arguments from Task Scheduler

Use this method if the decision to close the database is predetermined before the scheduled task starts.

By passing a custom argument through Task Scheduler, you can instruct Access on how to behave upon opening, avoiding the need for complex internal evaluations if the schedule dictates the action.

1
Modify the Scheduled Task

Open Windows Task Scheduler, locate your report email task, right-click it, and select 'Properties'. Go to the 'Actions' tab.

2
Add a Command Argument

Edit the 'Start a program' action. In the 'Add arguments (optional)' field, append a custom command such as /cmd "AutoClose" after the path to your database.

3
Read the Argument in VBA

Open your Access database. In your startup VBA script or form load event, use the Command() function to capture the argument passed by Task Scheduler.

4
Execute the Quit Command

Add an If statement in your VBA code: If Command() = "AutoClose" Then Application.Quit. Place this immediately after your email routine finishes to ensure the database closes only when scheduled.

Argument Formatting: Ensure there is a space before the /cmd switch in your Task Scheduler arguments to prevent formatting errors.
Free Microsoft Office alternative

Looking for a Lightweight Office Suite? Try WPS Office

While Microsoft Access handles specific database management needs, everyday tasks require robust word processing, spreadsheets, and presentation tools. WPS Office provides a powerful, free, and lightweight alternative for your document needs, ensuring excellent format compatibility and a seamless transition.

  1. 1. Download the Installer: Visit the official WPS Office website to download the free installation package for Windows, Mac, or Linux.
  2. 2. Install the Suite: Run the installer and follow the quick on-screen instructions to set up the software on your device.
  3. 3. Open Your Files: Launch WPS Office and directly open your existing Microsoft Word, Excel, and PowerPoint files without losing formatting.
Highly compatible with standard Microsoft Office formats (.docx, .xlsx, .pptx).Free, lightweight, and consumes minimal system resources.Familiar tabbed user interface to ensure a seamless migration.Built-in PDF editing tools for comprehensive document workflow management.
microsoft office alternative - wps office

Frequently Asked Questions

Can I schedule an Access macro directly from Task Scheduler?

Task Scheduler cannot run an Access macro directly. Instead, you schedule Microsoft Access to open your database file and use the /x command-line switch followed by your macro name to trigger it automatically upon opening.

Why does my Access database stay open as a background process?

If a VBA script crashes silently or an Application.Quit command is bypassed due to unhandled errors, the Access background process (MSACCESS.EXE) may remain active. Ensure your VBA code includes robust error handling.

Is it possible to use a batch script for this automation?

Yes, you can write a .bat or .vbs script to launch the Access database, pass necessary parameters, and manage process termination. You then schedule this script in Task Scheduler instead of calling Access directly.