Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Command Line Arguments

Status
Not open for further replies.

wurld2

Technical User
Jan 7, 2004
3
US
Hi everyone,
I know how to pass a single argument with '/cmd' and retrieve it inside VBA using the Command function. Is it possible to pass multiple arguments using '/cmd', and, if so, what is the syntax to retrieve them individually?

Thanks,
Chris
 
The command line arguments get passed as a single string via the /cmd switch. Use something like a semicolon to separate them though. then use the following code to parse the line, and get to the individual parameters:

CommandLineParms = Split(Command(), ";")
YourFirstArgument = CommandLineParms(0)
YourSecondArgument = CommandLineParms(1)
... and so on

You can get fancier than this if you want to allow variation in the order of the arguments, by allowing prefixing of each argument with an argument id; this would then mean re-splitting each argument above, and parsing appropriately.

You might also want to look at the lbound and ubound functions, which are useful for indicating how many elements are in the array generated by the split function.



Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Hi, I´ve benn reading VBA´s documentation and I´ve found out that the function Command() is not available for Ms Office (VBA) as it is for VB. Have You managed to make the above code work using VBA? I Can´t even use the '/cmd' without getting an error msg.
Anything would be really helpful.

Thanks.
 
I am not sure what you've been reading, but sounds like nonsence to me. The above code was published because it does work (Access 2000, and I'm pretty sure, from memory, 97)

How are you specifying your command line? Make sure you use the full path to the access executable, as opposed to just starting with the mdb filename and then relying on the mdb association with Access; eg.

"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" C:\yourpath\yourmdb.mdb /cmd a;b;c

NOT

C:\yourpath\yourmdb.mdb /cmd a;b;c

Whilst the latter will run the mdb, it wont pick up the command line parameters; I'm guessing this is the problem you're having.




Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Thanks Steve, I wasn't using the full path...
Anyway, knowing this, is it still possible to do the same thing invoking an excel file from internet explorer?
I need to display graphs using parameters via Intranet, but it seems that it'll be impossible to make if the application (excel, access, etc) needs to be called that way.


PD: I read about the command issue in excel's help. But it sounded crazy to me too.
 
excel - I really don't know; you may be better off trying the Microsoft Office forum for this one.

Good luck

Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top