4

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.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Tom Malkin
  • 2,134
  • 2
  • 19
  • 35
  • 2
    Have a look at https://support.office.com/en-ie/article/Command-line-switches-for-Access-558cfe1d-3c98-4292-bee8-1f5df9702bf1 – Fionnuala Apr 03 '17 at 06:38
  • 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 function – Tom Malkin Apr 03 '17 at 23:31

1 Answers1

14

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
Andre
  • 26,751
  • 7
  • 36
  • 80
  • 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? – Jaskier Jul 03 '20 at 16:00
  • 1
    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](https://access.uservoice.com/forums/319956-access-desktop-application/suggestions/12519978-for-security-support-passing-the-database-passwor). @Symon – Andre Jul 04 '20 at 09:02