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.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gustav BrockCIOCommented:
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 (Microsoft MVP/ EE MVE)President / OwnerCommented:
The command should be:

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

pcalabriaAuthor Commented:
@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?
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Gustav BrockCIOCommented:
It might be simpler to just let your initial code read the user name:

UserName = Environ("username")

Open in new window

and then take the necessary actions from this.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
<<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.

pcalabriaAuthor Commented:
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 (Microsoft MVP/ EE MVE)President / OwnerCommented:
Just be aware that if someone can get to the command box, they can by-pass your security.  

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.