Opening Microsoft Access with parameters
Asked Answered
C

1

5

Similar to the OpenArgs property of the Form object, am I able to open the Access Application itself with a passed parameter (say from a .bat file)?

Basically I'm looking to speed up the user's experience by having variable links to .bat files that open the same file, but to a different menu screen etc.

Conversation answered 3/4, 2017 at 4:41 Comment(2)
Have a look at support.office.com/en-ie/article/…Acquah
thanks @Fionnuala. The /x from that site I would have used, but I think the /cmd switch is more useful because I can do all the processing in the start up functionConversation
R
15

Use the /cmd command-line parameter to start Access, and the Commmand() function in Access-VBA to read it.

"C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE" D:\Work\myDb.accdb /cmd foo

and this function called by an Autoexec macro:

Public Function AutoExec()

    Dim sCmd As String

    ' ... other initializations ...

    ' Read /cmd command-line parameter
    sCmd = Command()

    Select Case sCmd
        Case "foo": Call Foo()
        Case "bar": Call Bar()
        Case Else: Debug.Print "No valid command-line parameter passed."
    End Select

End Function
Ramonaramonda answered 3/4, 2017 at 7:18 Comment(2)
Is it possible to use this process when the database has a password on it and uses the MS Access 'User Permissions' for .mdb files?Convince
You can specify the .mdw with /wrkgrp C:\FullPathTo\mysecurity.mdw. /cmd foo must be the last parameter. Specifying the database password via command-line is not possible: Link. @SymonRamonaramonda

© 2022 - 2024 — McMap. All rights reserved.