Open an Access form from command line with parameter

Z

Zarty

Is it possible to open an Access form from the command line with a parameter
so that the form opens up and displays at the record defined by that
parameter?

So, for example, if the main 'Primary Key' field at the top of the form was
called 'ID' with a numeric value, could that ID be passed in as a command
line parmater to open up the form on that record?

Thanks
Zarty
 
K

Krzysztof Pozorek [MVP]

(...)
Is it possible to open an Access form from the command line with a
parameter
so that the form opens up and displays at the record defined by that
parameter?

So, for example, if the main 'Primary Key' field at the top of the form
was
called 'ID' with a numeric value, could that ID be passed in as a command
line parmater to open up the form on that record?

Use the OpenArgs argument of the OpenForm method:
DoCmd.OpenForm "Form1",,,,,,YourID
http://msdn.microsoft.com/en-us/library/aa213973(office.11).aspx

K.P.
 
T

Tom van Stiphout

On Mon, 14 Jul 2008 05:56:00 -0700, Zarty

You can't open a form from the command line, but you can open a macro
from the command line, using the /x command line switch.
You can also open your app with the typical AutoExec macro, use the
/cmd command line switch to specify arguments, in AutoExec call
RunCode to start your VBA code, and in it use Command$ to read your
/cmd arguments.

The format of the arguments is mostly arbitrary; I prefer a
querystring like format:
launchform=frmSomething&ID=123
This can be Split() twice to get the arguments.

-Tom.
 
K

Klatuu

Yes, it is. on the command line, you add the /cmd and the value you want to
pass to the application. Then in the applcation, use the Command function to
return the value.
 
Z

Zarty

Thanks guys,

I'm going to use \cmd and pass in an argument that is the 'ID' number that
specifies the record on the form. I have put some code into

Function CheckCommandLine()
stLinkCriteria = Command()
DoCmd.OpenForm "MainFormt", , , "[ID] = " & stLinkCriteria
End Function

I then created an Autoexec macro to call the above CheckCommandLine() but
got a bit stuck with this because I can't find out how to call this function
from within Autoxec. If I select RunCode from within the AutoExec
form/wizard and I type in CheckCommandLine() in the 'Function name' field,
Autoexec can't find this function when it runs. Could do with some pointers
on this please.

Zarty
 
T

Tom van Stiphout

On Mon, 14 Jul 2008 08:29:00 -0700, Zarty

It needs a public function in a standard module.
-Tom.
 

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