Create desktop shortcut in VBA, with startup parameter/argument

In Access 2010/2013/2016 I'm using a function to create a desktop shortcut for a database - but I need to also supply a "/cmd" argument to do some detection when starting up the database - the parameter is put in the shortcut, but is ignored when starting up the database

Set scr = CreateObject("WScript.Shell")
Set scrLink = scr.CreateShortcut(strPath)
scrLink.TargetPath = scPath
scrLink.Arguments = "/cmd " & cmdPath
scrLink.IconLocation = iconPath

Open in new window

Mik MakConsultantAsked:
Who is Participating?
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.

George WaltonRemote Administrator LMCommented:
Execute your code and check the ShortCut, is it correct cmd line ? change it manually , will it work after that?

Perhaps you have problem in ShortCut text or in VB code
You had to create link to Access.exe with parameters (name of database, etc):
scPath = "c:\Program Files (x86)\Microsoft Office\root\Office16\MSACCESS.EXE" 'For Access 2016
scrLink.Arguments ="d:\tmp\DB.accdb /cmd Parm1 Parm2"

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
Mik MakConsultantAuthor Commented:
Hi als315 - I think you're quite right that it needs a program path to transfer the parameter - but if a program path needs to be included how can I make the shortcut function work across different installations ?
Mik MakConsultantAuthor Commented:
I can use SysCmd(acSysCmdAccessDir) :)
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
VB Script

From novice to tech pro — start learning today.