vba 使用参数打开 Microsoft Access

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43176599/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 12:23:15  来源:igfitidea点击:

Opening Microsoft Access with parameters

vbabatch-filems-accessms-office

提问by Harlekuin

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

与Form 对象的OpenArgs属性类似,我是否能够使用传递的参数(例如来自 .bat 文件)打开 Access 应用程序本身?

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.

基本上,我希望通过具有指向 .bat 文件的可变链接来加快用户体验,这些链接打开相同的文件,但指向不同的菜单屏幕等。

回答by Andre

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

使用/cmd命令行参数启动Access,Commmand()使用Access-VBA中的函数来读取它。

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

and this function called by an Autoexecmacro:

这个函数被一个Autoexec宏调用:

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