Page 1 of 1

Batch file doesn't process parameter

Posted: 25 Mar 2010 04:26
by avalancha
Hey out there!

I have a quiestion concerning a .bat of mine and I hope this is the right spot to post it:

My task is the following: I need to write a batch that starts an Access database and processes a parameter to it so that a module I created can catch it as the following:

Code: Select all

If Command = "test" Then


But the batch has to work with relative paths and that's where the problems come in: it all works fine like this:

Code: Select all

"C:\Program Files\Microsoft Office\Office11\Msaccess.exe" "C:\Program Files\Subdirectory\business.mdb" /cmd "orders"


but as soon as i try it like that:

Code: Select all

".\business.mdb" /cmd "orders"


the database opens up (it's always in the same folder) but the parameter is not processed and the module does not work!

I really need help here, thanks in advance!!

Best regards,
Patrick

Re: Batch file doesn't process parameter

Posted: 25 Mar 2010 11:44
by aGerman
Try this

Code: Select all

start "" "msaccess.exe" "%~dp0business.mdb" /cmd "orders"

or

Code: Select all

start "" "msaccess.exe" "%cd%\business.mdb" /cmd "orders"


The option /wait means that your batch will not continue until you close Access.

Code: Select all

start "" /wait "msaccess.exe" "%cd%\business.mdb" /cmd "orders"


Regards
aGerman

Re: Batch file doesn't process parameter

Posted: 25 Mar 2010 12:25
by avalancha
yea I knew "/wait" before but hey:
oh... my... god
you are the BEST!!!! It works!!

Du kannst dir nicht vorstellen was für einen Gefallen du mir grade getan hast und wie viele Tage Rumgemurkse damit zu Ende gehen! DANKE!

Best regards,
Patrick

Re: Batch file doesn't process parameter

Posted: 25 Mar 2010 13:13
by aGerman
You're welcome.
For your understanding:
The dot (.\) is only relative to your batch file, but not to msaccess.exe. It needs the entire path.
Because /cmd is a switch of msaccess.exe you can't use it only with the .mdb file.

Grüße aus Thüringen nach Baden-Württemberg :wink:

Re: Batch file doesn't process parameter

Posted: 25 Mar 2010 14:16
by avalancha
ok well talking already about understanding... so what does the

Code: Select all

%~dp0
mean?
"Look in the same folder" or something similar?

Greetings my friend :mrgreen:

Re: Batch file doesn't process parameter

Posted: 25 Mar 2010 14:34
by aGerman
Well, I'm sure that you know parameters like %1, %2 etc.
%0 is a special kind of parameter and contains the "own call" of the batch file (means something like the full name). You can use options for this parameters, so the d is for drive and the p is for path. All in all %~dp0 returns drive and path of your batch file. For all those options have a look to the help of call (call /?).
%cd% is similar, but not the same. It contains the current working directory of your batch file, but this can be changed using CD or PUSHD / POPD commands.

Hope this will clarify some more, my friend :lol:

Re: Batch file doesn't process parameter

Posted: 26 Mar 2010 00:56
by avalancha
Jep, sure did.
You know, I'm rather a C programmer and quite new to this stuff... I had never heard about this parameter before, therefore again: tanks

Patrick