Need to start mdb using Startup command-line options and pass in a parameter

M

moondaddy

from a .net winforms application I need to start a MS Access 2003
application using the startup command-line and shell. I can start the
application OK, but need to call a public function or a macro that will call
the function and pass in a parameter string. how can I do this and what's
the syntax?

Dim Param As String = "Bla1, bla2, bla3"
Dim FuncName As String = "myStartupFunc"
Dim stAppName As String
stAppName = """C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE"" " &
_
"""D:\nwis\Apps\LandMan\VS\TransAct\TransAct\Stallion\TransAct_Stallion_Remote.mdb"""

'This line works good for opening the app
Dim ID As Int32 = Shell(stAppName, AppWinStyle.NormalFocus, False, -1)

But how do I change it to call myStartupFunc and pass Param into
myStartupFunc?

Using the interop libraries in .net are not a good option do to
complications involved in installing on lots of remote computers, licensing,
etc. We've had lots of problems with it and both MS and InstallShield are
stumped. Using the shell command would be way cleaner and less error prone.

Thanks.
 
M

Marshall Barton

moondaddy said:
from a .net winforms application I need to start a MS Access 2003
application using the startup command-line and shell. I can start the
application OK, but need to call a public function or a macro that will call
the function and pass in a parameter string. how can I do this and what's
the syntax?

Dim Param As String = "Bla1, bla2, bla3"
Dim FuncName As String = "myStartupFunc"
Dim stAppName As String
stAppName = """C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE"" " &
_
"""D:\nwis\Apps\LandMan\VS\TransAct\TransAct\Stallion\TransAct_Stallion_Remote.mdb"""

'This line works good for opening the app
Dim ID As Int32 = Shell(stAppName, AppWinStyle.NormalFocus, False, -1)

But how do I change it to call myStartupFunc and pass Param into
myStartupFunc?

Using the interop libraries in .net are not a good option do to
complications involved in installing on lots of remote computers, licensing,
etc. We've had lots of problems with it and both MS and InstallShield are
stumped. Using the shell command would be way cleaner and less error prone.


Check Access Help for Startup command-line options,
especially
/X macro
and
/cmd
 
M

moondaddy

Thats the first place I went, but saw no mention of passing in parameters to
a macro or function. Any more advice?
 
P

Paul Overway

First, you need to shell with the /cmd switch and your parameters. Then
within the MDB, you have to parse the Command function. See help for
Command.

--
Paul Overway
Logico Solutions
http://www.logico-solutions.com


moondaddy said:
Thats the first place I went, but saw no mention of passing in parameters
to a macro or function. Any more advice?
 
M

moondaddy

Thanks but I've read the documentation on command and startup command in to
..net and access and there's no mention of passing in the parameter that my
function in access is expecting. only parameters for the command line
switches. It would be nice if someone who knows something about this could
show an example of how it would work.

I found a work around to make things work, but its a bit of a hack to say
the least, but it WORKS.

code in vb.net:


'Build the mdb path and access exe path and add on a switch to run a macro
in access. this macro will then call my function in a module.
stAppName = """C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE"" " &
_
"""D:\nwis\Apps\LandMan\VS\TransAct\TransAct\Stallion\TransAct_Stallion_Remote.mdb"""
& "/x mcrStartupGroup.mcrStartApp"

'now execute the command in the .net app.
Dim ID As Int32 = Shell(stAppName, AppWinStyle.NormalFocus, False, -1)

Now the HACK. In the .net app just before these lines execute I created a
text file which contains a text string with about 15 parameters comma
delimited. Code above executes and the function in access is called. The
function in Access opens this text file and reads the string, parses out the
parameters, closes the text file and then deletes it so in all it only
exists for a split second. lastly, access has its parameters to start
running the app.
whew.



--
(e-mail address removed)
Paul Overway said:
First, you need to shell with the /cmd switch and your parameters. Then
within the MDB, you have to parse the Command function. See help for
Command.
 
P

Paul Overway

If you're passing that many parameters, it could be the problem....i.e.,
there is might a limit in respect to length. Nevertheless, if your command
line parameters were a reasonable length, you'd pass them like this

msaccess.exe /cmd Parm1|Parm2|Parm3|Etc

Then in the startup code for the database you would parse the Command
function....which would contain.

Parm1|Parm2|Parm3|Etc

If that doesn't work for for your needs, you might try using automation to
start Access and open the database...then pass the parameters to fields on a
hidden form...then execute some method within that form to do whatever it is
you need to do and close the form. Air code follows...

Set objAccess = CreateObject("Access.Application")
objAccess.OpenCurrentDatabase "path to file"
objAccess.Docmd.OpenForm "someform",,,,,acHidden
Set frm = objAccess.Forms("someform")
frm.txtField1 = Parm1
etc..

frm.DoSomething

BTW...you might want to be careful how you phrase comments...you sorta
implied that I/others don't know anything? Keep in mind that you are asking
for VB.Net help in a Access NG....so, translating Access VBA code really
falls to you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top