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
Opening Microsoft Access with parameters
提问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 /cmd
command-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 Autoexec
macro:
这个函数被一个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