访问:Shell cmd 打开MDB
我一直在使用以下命令通过 VBA 打开另一个 MDB Access 文件:
Shell "cmd /c " & Chr(34) & strNewFullPath & Chr(34), vbHide
strNewFullPath 是 MDB 文件的完整路径。 使用 Access 2010 时工作正常,但无法在 Access 2003 上运行。 如果我在 XP DOS 终端中运行该命令,它就会运行。
我还可以使用哪些其他命令可以在 Access 2003 及以上版本上与 Access Runtime 配合使用?
I have been using the following command to open another MDB Access file via VBA:
Shell "cmd /c " & Chr(34) & strNewFullPath & Chr(34), vbHide
strNewFullPath is the full path of the MDB file.
Works fine when using Access 2010, but doesn't run on Access 2003.
If I run the command in a XP DOS terminal it DOES run.
What other command can I use that should work on Access 2003 up and with the Access Runtime?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果要使用 Access VBA 打开另一个 Access 应用程序实例中的数据库,可以执行以下操作:
将 UserControl 设置为 True 使新的应用程序实例在该过程完成后保持打开状态。
如果您希望隐藏新的 Access 实例,请包括:
我建议使用此方法,因为它还为您提供了一种通过 objApp 对象变量自动创建新应用程序实例的方法。但是,如果您对自动化新实例不感兴趣,那么只有当您无法使任何其他方法发挥作用时,此方法可能才有用。
If you want want to use Access VBA to open a database in another Access application instance, you can do this:
Setting UserControl to True leaves the new application instance open after the procedure finishes.
If you want the new Access instance hidden, include:
I'm suggesting this approach because it also gives you a way to automate the new application instance through the objApp object variable. But, if you're not interested in automating the new instance, this approach will probably only be useful if you can't make any other method work.
尝试使用 Windows 脚本主机对象模型 (WSHOM ):
Windows 文件关联应允许两种类型的文件在其本机应用程序中打开。
用法示例:
可选参数:
Run 方法有两个可选参数。请注意,其中大部分内容是从 MSDN 复制的:
intWindowStyle(整数)
0 到 10 之间的数字:
<块引用>
0 - 隐藏窗口并激活另一个窗口。
1 - 激活并显示一个窗口。如果窗口最小化或最大化,系统
将其恢复到原来的大小和位置。一个应用程序应该
第一次显示窗口时指定此标志。
2 - 激活窗口并将其显示为最小化窗口。
3 - 激活窗口并将其显示为最大化窗口。
4 - 以最新的大小和位置显示窗口。活跃的
窗口保持活动状态。
5 - 激活窗口并以其当前大小和位置显示它。
6 - 最小化指定窗口并激活 Z 顺序中的下一个顶级窗口。
7 - 将窗口显示为最小化窗口。活动窗口保持活动状态。
8 - 显示当前状态的窗口。活动窗口保持活动状态。
9 - 激活并显示窗口。如果窗口最小化或最大化,系统会将其恢复到原始大小和位置。应用程序应在恢复最小化窗口时指定此标志。
10 - 根据启动应用程序的程序的状态设置显示状态。
我不知道该参数的默认值。请注意,有些程序只是忽略您设置的任何值(我无法告诉您哪些值)。
bWaitOnReturn(布尔值)
对于异步代码,设置为False。 Run 方法在完成之前将控制权返回给调用程序。默认值为False。
Try using Windows Scripting Host Object Model (WSHOM):
The Windows file association should allow both types of files to open in their native application.
Sample Usage:
Optional Arguments:
There are two optional arguments for the Run method. Please note that much of this is copied from MSDN:
intWindowStyle (integer)
A number from 0 to 10:
I am not aware of the default value for this parameter. Note that some programs simply ignore whatever value you set (I couldn't tell you which ones).
bWaitOnReturn (boolean)
Set to False for asynchronous code. The Run method returns control to the calling program before completing. Default is False.
您可以使用 Win32 API 查找与文件类型关联的 EXE 名称,并将其添加到您的 shell 命令中,如下所示:
You can use the Win32 API to find the EXE name associated with the file type and prepend it to your shell command like this:
shell 命令的问题是 cmd 提示符并不总是支持使用文件扩展名来启动程序。事实上,你最好使用
“开始”“带有.扩展名的文件的路径”。
上面与单击非常相似。
但是,您真正想要做的是启动 msacces.exe 并提供文件的路径名以供打开。对于运行时安装尤其如此。
因此您的代码应如下所示:
因此上面使用了 msaccess.exe 的完整路径名。它已经在 xp、vista、win7 等上进行了测试,它总是对我有用。
在 Access 多个版本或使用运行时的情况下,您可能不希望使用扩展名来启动文件。因此,这可确保您使用与当前运行的相同版本和相同的 .exe。因此,上述代码会提取您正在使用的当前 msaccess.exe 路径,而不是基于文件扩展名的路径。
The problem with your shell command is the cmd prompt don't always support using the file extension to start a program. In fact, you better off to use
Start "path to some file with .extension"
The above is quite much the same as clicking.
However, what you really want to do is launch the msacces.exe and SUPPLY the path name to the file for it to open. This is especially the case with a runtime install.
So your code should look like this:
So the above uses the full path name to msaccess.exe. It been tested on xp, vista, win7 etc, and it always worked for me.
And in the case of more than one version of Access, or that of using a runtime, you may not want to use the extension to launch the file. So this ensures that you are using the SAME version and same .exe that you are currently running. So the above code pulls the current msaccess.exe path you are using, not one based on file extension.
我在 Access 2003 中工作时使用此函数:
这在运行时模式下有效:)
I use this function when working in Access 2003:
This does work in Runtime mode : )
这是我用来使它与 accdr 一起工作的一个轻微修改,其中需要使用运行时开关。
Here is a slight revision I used to make it work with accdr, where it is required that there be a runtime switch used.