Avatar of pcalabria
Flag for United States of America asked on

Need help reading a command line parameter in MS Access MDE

I need help getting command line parameters working with MS Access mde files.

When I use a batch file to start MS Access using the /cmd switch all works fine when I start the mdb... however, when I compile the program the mde does not work.

The code I execute to read the parameter is:

This is the line I use in the BAT file to start and test the MDB. Everything works fine.
"C:\Program Files\Microsoft Office\Office\MSAccess.exe" "c:\disti-master\database\Inventory_Program.mdb" /cmd start MAT

Once compiled to an MDE I tired adding this line to the BAT file.  This line does not work.  It does not return an error, it simply does not read the command line parameter.

"c:\disti-master\database\Inventory_Program.mde" /cmd start MAT

I also tried:

"c:\disti-master\database\Inventory_Program.mde" /cmd "start MAT"

Please help by providing me with a way to have access read the command line parameter "start MAT" when the mde is executed.

Microsoft Access

Avatar of undefined
Last Comment
Jim Dettman (EE MVE)

8/22/2022 - Mon
Gustav Brock

Try moving the mdb and mde to subfolder of a safe folder like %LocalAppData%.

It will resolve to something like: C:\Users\<UserName>\AppData\Local
Jim Dettman (EE MVE)

The command should be:

"C:\<path to MSACCESS.EXE>\MSACCESS.EXE"  "c:\disti-master\database\Inventory_Program.mde" /cmd start MAT


@Gustav  Thanks for your suggestion.  Due to the fact that we have Group Policies setup which completely restricts other directories, I have strong incentives to keep the program in the same directory on all the machines.

@JIM  Your solution works, however, this solution does not solve my problem.  

I created support for command line parameter to automatically start the program using different modules for different users, without these users first going through usual log-in and copyright screens.  For example, when MAT starts the program, the program should skip all the nonsense...load the form he uses... populate the form as MAT requires... and then start running automatically.

I hoped to achieve this by adding something like C:\ProgramName.mde /cmd start MAT to AD as a log-in script.  This way any computer MAT uses will yield the same results.  The problem with specifying the full path for MSACCESS.EXE is that XP and Win7 ( and perhaps Win10 and the Access 2016 runtime) us different paths.   Is there any way you know that will allows MAT to always get a special start up?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Gustav Brock

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Jim Dettman (EE MVE)

<<It might be simpler to just let your initial code read the user name:>>

If this is just user based start-up, then that's the route I would take, but I would use the Windows API to get the user name.   Using environ() can allow to easily spoof another user.

<< C:\ProgramName.mde /cmd start MAT to AD as a log-in script.  >>

  You can't, unless you assign different scripts to different people as you must call the MSACCESS.EXE to get the command line options to work.

 By referencing the MDE, your relying on Windows to find the executable through the explorer shell, and the default there is to only accept the name of the file you want to open.  The rest is ignored.


Thanks... I split the points as Jim answered the question and taught me how to use the /cmd option, however, Gustav gave me the solution I needed to solve my problems.

Thanks once AGAIN to BOTH of you!!!
Jim Dettman (EE MVE)

Just be aware that if someone can get to the command box, they can by-pass your security.  

Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.