It can be done, but it's not quite as simple as that.
There's a /cmd switch that can be specified when you open the database, and
anything passed after the switch can be read inside of Access using the
Command function. The thing is, though, that /cmd is a switch for Access
itself, not for mdb files. That means that you must include the full path to
msaccess.exe in order to use that switch:
"C:\Program Files\Microsoft Office\Office\MSAccess.exe" "C:\Program
Files\Microsoft Office\Office\Samples\Northwind.mdb" /cmd frmTenant,ID=345
or you can use ; instead of /cmd
"C:\Program Files\Microsoft Office\Office\MSAccess.exe" "C:\Program
Files\Microsoft Office\Office\Samples\Northwind.mdb" ;frmTenant,ID=345
(either way, it must be the last switch specified.)
Okay, so now you've got a way to pass something to your application. You
have to be able to do something in your application once you receive that
information. The simplest approach would like be to have a start up form
that looks to see whether or not something was passed using the /cmd switch.
That code would go into the form's Load event, and look something like:
Private Sub Form_Load()
If Len(Command) > 0 Then
' something was passed
Else
' nothing was passed
End If
End Sub
What is it you're going to do? Assuming what's passed is frmTenant,ID=345,
you can use the Split function to parse that into the form name and the
lookup criteria, and use those in conjunction with the FileOpen method:
Dim varParms As Variant
varParms = Split(Command, ",")
If UBound(varParms) = 1 Then
DoCmd.OpenForm varParms(0), acNormal, , varParms(1)
End If
That'll open the form passed in front of the comma, using whatever was
passed after the comma as a Where condition. Note that that means that that
will be the only row displayed on the form. If that's not what you want, you
have the option of passing what's after the comma as the form's OpenArgs
parameter, and having code in the Load event of each possible form you'll be
opening to read what's in the OpenArgs parameter and use that to position
the current row on the form. However, that's more code than I'm willing to
type at the moment. <g>