Need help reading a command line parameter in MS Access MDE

pcalabria
pcalabria used Ask the Experts™
on
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:
strCommand=Command()

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.

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
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)President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012

Commented:
The command should be:


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

Jim.

Author

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?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Most Valuable Expert 2015
Distinguished Expert 2018
Commented:
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.
Jim Dettman (EE MVE)President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012

Commented:
<<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.

Jim.

Author

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 (EE MVE)President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012

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

Jim.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial