Open an Access 2013 Database from a Batch File with a Command-Line Value
Question details
Pass a file path, file name, or another value from a batch file to an Access 2013 database when it opens.

- 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.
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.
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.
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.
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.
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".

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.

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.




