Pass arguments to Access 2000 via command line

Is there any way to pass an argument into an Access MDE application via a command line?
We have a .NET application that needs to shell out to Access and open a form in our own Access 2000 application on a given record, so we need to pass the order# into the form while loading the .MDE app.

One solution, which we do not want to use, is to write out the order# to a temp table and then have the Access app read from that table when it opens because of multi-user issues.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
Use /CMD followed by the arguments.  Best if it is the last switch used.   Within Access, use Command$ to get the arguments passed.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
Here's a couple handy functions.  Note that you will need to modify slightly (error handler).


Public Sub GetCommandLine(Optional intMaxArgs As Integer)

    Const RoutineName = "GetCommandLine"
    Const Version = "2.0"

    'Declare variables.
    Dim strChr As String
    Dim strCmdLine As String
    Dim strCmdLnLen As Integer
    Dim intInArg As Integer
    Dim intI As Integer
    Dim intNumArgs As Integer

    'See if intMaxArgs was provided.
10  If IsMissing(intMaxArgs) Then intMaxArgs = 10

    'Make array of the correct size.
20  ReDim gvarCmdArgArray(intMaxArgs - 1)
30  intNumArgs = 0
40  intInArg = False

    'Get command line arguments.
50  strCmdLine = Command()
60  strCmdLnLen = Len(strCmdLine)

    'Go thru command line one character at a time.
70  For intI = 1 To strCmdLnLen
80      strChr = Mid(strCmdLine, intI, 1)

        'Test for space or tab.
90      If (strChr <> " " And strChr <> vbTab) Then
            'Neither space nor tab.
            'Test if already in argument.
100         If Not intInArg Then
                'New argument begins.
                'Test for too many arguments.
110             If intNumArgs = intMaxArgs Then Exit For
120             intNumArgs = intNumArgs + 1
130             intInArg = True
140         End If
            'Add character to current argument.
150         gvarCmdArgArray(intNumArgs - 1) = gvarCmdArgArray(intNumArgs - 1) + strChr
160     Else
            'Found a space or tab.
            'Set intInArg flag to False.
170         intInArg = False
180     End If
190 Next intI

    ' Don't want to do this as some arguments may be optional.
    'Resize array just enough to hold arguments.
    'ReDim Preserve gvarCmdArgArray(intNumArgs - 1)

End Sub
Public Function GetCommandLineArg(intArgNumber) As Variant

    ' Returns an argument from the command line
    ' Null is returned on Error or non-existant argument

    Const RoutineName = "GetCommandLineArg"
    Const Version = "2.0"

10  On Error GoTo GetCommandLineArgError

20  If intArgNumber > UBound(gvarCmdArgArray()) Then
30      GetCommandLineArg = Null
40  Else
50      GetCommandLineArg = gvarCmdArgArray(intArgNumber)
60  End If

70  On Error Resume Next

80  Exit Function

90  UnexpectedError ModuleName, RoutineName, Version, Err.Number, Err.Description, Err.Source, VBA.Erl
100 GetCommandLineArg = Null
110 Resume GetCommandLineArgExit

End Function
'  Write entry into system log file.
Function LogSystemEvent(intEventType As Integer, strEventMessage As String) As Integer

    Const RoutineName = "LogSystemEvent"
    Const Version = "2.0"

    Dim db As DAO.Database
    Dim rst As DAO.Recordset

10  On Error GoTo LogSystemEventError

20  LogSystemEvent = True

    ' Add record to event table
30  Set db = CurDb()
40  Set rst = db.OpenRecordset("tblSystemLog", dbOpenDynaset)
50  rst.AddNew
60  rst![Type] = intEventType
70  rst![Message] = strEventMessage
80  rst.Update

90  On Error Resume Next

100 rst.Close
110 Set rst = Nothing

120 Set db = Nothing

130 Exit Function

140 UnexpectedError ModuleName, RoutineName, Version, Err.Number, Err.Description, Err.Source, VBA.Erl
150 LogSystemEvent = False
160 Resume LogSystemEventExit

End Function

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Here is a link to the relevant Help entry -

The article omits a salient point and that is how to retrieve the /cmd value.  Another source (which must remain nameless) suggested using Command() to retrieve the value that follows /cmd.
rfmassaAuthor Commented:
Thank you!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.