Office Settings & Configuration

Open an Access 2013 Database from a Batch File with a Command-Line Value

Bushra ParveenBushra Parveen Nov 25, 2026 868 views

Question details

Pass a file path, file name, or another value from a batch file to an Access 2013 database when it opens.

Open an Access 2013 Database from a Batch File with a Command-Line Value
Product
Microsoft Access 2013
Device & OS
not provided
Scenario
A custom file extension is associated with a batch file that may perform additional actions before starting an Access database.
Observed behavior
The database opens and can retrieve the value supplied by the batch file.
Before you start

Locate your database file and MSACCESS.EXE, and check that the batch file receives the value you want to pass as its first argument. If you use a custom file extension, verify that its association invokes the batch file with the selected file path.

Solution 1Recommended

Pass the value with the Access /cmd switch

Use this method when a batch file needs to launch Access and make an argument available to VBA.

1
Add the launch command

Open your batch file in a text editor and add: start "" "C:\Path\To\MSACCESS.EXE" "C:\Path\To\myprogram.accdb" /cmd "%~1". Replace both paths with the actual Access executable and database paths. The %~1 expression supplies the batch file's first argument without its surrounding quotes.

2
Read the value in Access

In Access, open the startup form in Design View, select its On Load event, and choose Event Procedure. Add MsgBox Command() inside the Form_Load procedure to display the value passed after /cmd.

3
Set the startup form and test

In Access, choose File > Options > Current Database and select the form under Display Form. Save the changes, close the database, and run the batch file with a test argument, such as launch.bat "C:\Files\example.xyz".

Pass the value with the Access /cmd switch
Handle the returned value: Use Command() in your VBA code instead of MsgBox to process the value. If your launch method includes surrounding quotation marks in the returned string, remove them before using the path.
Free Microsoft Office alternative

Use WPS Office for Everyday Office Documents

WPS Office is a free, lightweight alternative for working with documents, spreadsheets, and presentations. Its familiar interface and Microsoft Office format support help make migration straightforward. It does not replace Access or fix Access command-line behavior.

Free, lightweight tools for common office tasksCompatible with Microsoft Word, Excel, and PowerPoint formats, including DOCX, XLSX, and PPTXA familiar interface that makes it easy to move from Microsoft OfficeWork with spreadsheet data alongside your Access-based workflow
QA img-9

Frequently Asked Questions

How do I pass a fixed value instead of a file path?

Replace "%~1" after /cmd in the batch file with a fixed value, such as "somecommandhere". Read it in Access VBA with Command().

Where should I put the VBA code that reads the argument?

For a startup form, open it in Design View and add the code to its On Load event procedure. Set that form as the Display Form under File > Options > Current Database.

Why does Command() return an empty value?

Check that the launch command includes /cmd followed by a value. If you use "%~1", also confirm that the batch file was invoked with a first argument.

Can the batch file perform other actions before opening Access?

Yes. Add the required batch commands before the line that launches MSACCESS.EXE with the database path and /cmd argument.