Command-line switches for Access

This article shows you how to customize the way that Microsoft Office Access 2007 starts by adding switches and parameters to the startup command. For example, you can have Office Access 2007 open a specific file or run a specific macro when it starts.

Command line switches are also called command-line options. Depending on what they do, some switches require parameters, and some do not.

If you want to use a switch and any associated parameters just one time, you can type the command string in the Run box (in Microsoft Windows, click the Start button, and then click Run). The command string consists of the command that starts the program — in this case, Msaccess.exe — followed by a combination of switches and parameters. If you want to use the same switch and associated parameters many times, you can create a desktop shortcut that always starts the program by using the same switch and parameters. This article discusses how to do both, and contains a table that lists all of the switches and parameters that are available in Office Access 2007.

In this article


Introducing commands, switches, and parameters

Each time that you start Access by clicking the Access program icon or the program name on the Start menu, you are actually running the Msaccess.exe command, although you do not usually type the command or even see it.

You can change certain aspects of how the program starts by adding subcommands called switches to the Msaccess.exe command. A switch appears as a space after the main command, followed by a slash mark (/) and the name of the switch. The switch is sometimes followed by another space and then one or more specific instructions called parameters, which give the program further information about how to run the Msaccess.exe command. For example, the following command instructs Access to start and then open the specified file for read-only use:

msaccess.exe /ro "c:\My Folder\My Database.accdb"

In this example, the switch is /ro, and the parameter is "c:\My Folder\My Database.accdb". Note that the file path in this case is set in quotation marks because it contains spaces. When the file path does not contain spaces, quotation marks are not necessary.

In Office Access 2007, you can omit msaccess.exe and begin the command with the full file path, followed by switches and parameters. For example, you can type the above command as follows:

"c:\My Folder\My Database.accdb" /ro

 Note   For .accdb, .adp, or .mdb files, be sure that Access is not already running when you issue a command that does not include msaccess.exe. If Access is already running, no command-line switches will be passed. However, when you open an .accdr, an .mde, an .accde, or an .ade file, a new instance of Access is always started, so command-line switches will work normally.

Top of Page Top of Page

Use a switch once by adding it to the Run command

  1. In Windows, click the Start button, and then click Run.
  2. In the Run box, type msaccess.exe, or click Browse to locate it.
  3. Type a space, and then type the switch and any parameters. You can have multiple switches and parameters in one command. For example, to open a specific database in read-only mode and then run a specific macro within that database, you would type:

    msaccess.exe /ro "c:\MyFolder\MyDatabase.accdb" /x MyMacro

The next time that you start Access without command line switches, the program starts according to its defaults. To make your customized startup available for repeated uses, see the following section.

 Notes 

  • Switches and parameters are not case-sensitive. For example, /RO functions the same as /ro.
  • Include one blank space before each switch and one before each parameter.

Top of Page Top of Page

Make a switch available for reuse by creating a shortcut

First, verify the location of the Msaccess.exe file on your computer. If you accepted the default folder locations when you installed Access, the Msaccess.exe file is typically located at:

C:\Program Files\Microsoft Office\Office12\msaccess.exe

If you do not find the Msaccess.exe file at that location, search for the file and make a note of the full path.

  1. Right-click the Windows desktop, point to New, and then click Shortcut on the shortcut menu.
  2. On the first page of the Create Shortcut Wizard, in the Type the location of the item box, type a quotation mark ("), enter the full path for the Msaccess.exe file (including the file name), and then type a quotation mark. (Alternatively, click Browse to locate and select the file. In this case, the quotation marks are added automatically.)
  3. Following the closing quotation mark, type a space, and then type the switch and any parameters. If the parameter is a file path that includes spaces, it also must be enclosed in quotation marks. For example:
"c:\program files\microsoft office\office12\msaccess.exe" /ro "c:\My Folder\My Database.accdb"
  1. Click Next.
  2. In the Type a name for this shortcut box, type a name for the shortcut, and then click Finish.

The wizard creates the shortcut and places it on the desktop.

  1. Whenever you want to start Access in this particular customized way, double-click the shortcut.

 Tip   To add the desktop shortcut to the Start menu, right-click the shortcut, and then click Pin to Start menu on the shortcut menu.

You can create a variety of shortcuts, each of which applies different switches and parameters to the program at startup.

 Notes 

  • Switches and parameters are not case-sensitive. For example, /RO functions the same as /ro.
  • Include one blank space before each switch and one before each parameter.

Top of Page Top of Page

Available switches and parameters

The following table lists all of the switches and parameters that are available in Office Access 2007.

Switch Parameter Description
None database Opens the specified database or Microsoft Access project. Include a path, if necessary. If you include a path that contains spaces, enclose the path in quotation marks.
/excl None Opens the specified Access database for exclusive (exclusive: A mode of access to data in a database that is shared over a network. When you open a database in exclusive mode, you prevent others from opening the database.) access. To open the database for shared use in a multiuser (multiuser (shared) database: A database that permits more than one user to access and modify the same set of data at the same time.) environment, omit this switch. Applies to Access databases only.
/ro None Opens the specified Access database or Access project for read-only use.
/runtime None Specifies that Access will start with runtime version options.
/user user name Starts Access by using the specified user name. Applies to Access 2002-2003 and earlier databases only.
/pwd password Starts Access by using the specified password. Applies to Access 2002-2003 and earlier databases only.
/profile user profile Starts Access by using the options in the specified user profile instead of the standard Windows Registry settings created when you installed Access. This replaces the /ini switch used in versions of Access prior to Access 95 to specify an initialization file.
/compact target database or target Access project

Compacts and repairs the Access database, or compacts the Access project that was specified before the /compact switch, and then closes Access. If you omit a target file name following the /compact switch, the file is compacted to the original name and folder. To compact to a different name, specify a target file. If you include a path that contains spaces, enclose the path in quotation marks.

If you specify a file name in the target database or target Access project parameter but you don't include a path, the target file is created in the default database folder that is specified in Access. You can change this setting in the Access Options dialog box.

In an Access project, this option compacts the Access project (.adp) file but not the Microsoft SQL Server database.

/repair None Repairs the Access database that was specified before the /repair switch, and then closes Access. In Microsoft Access 2000 and later, compact and repair functionality is combined under /compact. The /repair switch is supported for backward compatibility.
/convert target database Converts a previous-version Access database or Access project to Access 2007 file format, renames the new file, and then closes Access. You must specify the source database before you use the /convert switch.
/x macro

Opens the Access database that was specified before the /x switch, and then runs the specified macro. Another way to run a macro when you open a database is to create a macro named AutoExec.

Macros can contain viruses, so you must be careful about running them. Take the following precautions: run up-to-date antivirus software on your computer; use the Trust Center to disable all macros except those that are digitally signed; maintain a list of trusted sources of macros.

/cmd None

Specifies that what follows on the command line is the value that will be returned by the Command function. This option must be the last switch on the command line. You can use a semicolon (;) as an alternative to /cmd.

Use this switch to specify a command-line argument that can be used in Visual Basic for Applications (VBA) (Visual Basic for Applications (VBA): A macro-language version of Microsoft Visual Basic that is used to program Microsoft Windows-based applications and is included with several Microsoft programs.) code.

/wrkgrp workgroup information file Starts Access by using the specified workgroup information file. Applies to Access 2002-2003 and earlier databases only.

Top of Page Top of Page

 
 
Applies to:
Access 2007