Access 2010 64 位有“打开文件”对话框吗?
如何获得 Access 2010 64 位的“打开文件”对话框?通常我会使用通用对话框控件,但它是 32 位的,不能与 Access 2010 64 位一起使用。
How do I get an Open File dialog for Access 2010 64bit? Normally I would use the common dialog control but that is 32bit and cannot be used with Access 2010 64 bit.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可以使用内置的文件对话框。它自 access 2003 起就存在。
如果您愿意,可以后期绑定:
以上需求:Microsoft Office 14.0 对象库
如果删除对 14.0 对象库的引用,则以下内容
代码无需任何引用即可工作:
因此,上述代码适用于 2003 年以后的运行时版或普通版,也适用于 32 或 64 位版本的 access 2010。
You can use the built in file dialog. It been there since access 2003.
You can late bind if you wish:
above needs: Microsoft Office 14.0 Object library
If you remove the reference to the 14.0 object library, then the following
code will work without any references:
So, above works in runtime or regular edition from 2003 onwards, and also works for either 32 or 64 bit editions of access 2010.
我从未使用过打开文件对话框的控件,因为无论如何它只是 API 调用的包装器。
调用标准 Windows 文件打开/保存对话框 此外,还可以进行分发和保存控件的版本控制问题,因此我尽力避免它们。
I've never used a control for the open File dialog as it's just a wrapper for the API call anyhow.
Call the standard Windows File Open/Save dialog box In addition there can be distribution and versioning problems with controls so I do my best to avoid them.
我花了很长一段时间来解决这个问题......
你上面所说的一切都有效,但还有最后一点要添加......在WITH OFN声明下,你需要更改
为
然后一切正常。
I was working with this problem for a long while...
Everything you have said above works but there is one last piece to add ... under the WITH OFN declaration you need to change
to
And then everything works.
这个人有一个工具,可以生成与 64 位兼容的打开文件的代码。它是免费软件。
http://www.avenius.de/en/index.php?产品:IDBE_Tools
这是唯一有效的方法。
This guy has a tool that generates code that is 64 bit compatible for opening a file. It is freeware.
http://www.avenius.de/en/index.php?Products:IDBE_Tools
This was the only thing that worked.
首先,“CommonDialog Class”似乎无法在 32 位版本的 Office 上运行。它给出了相同的 OleDb 错误。正如一位评论者指出的那样,这不是您应该使用的控件。虽然您可能可以使用另一个 ActiveX 控件,但实际上并不能保证它在您想要部署数据库的每台计算机上都可用。我的开发盒上装有 Visual Studio 6、VS 2008 和 VS 2010,此外还有 Office 和其他程序,所有这些程序都提供了典型用户不可能拥有的 ActiveX DLL。此外,其中许多库不可重新分发,或者造成独特的安装障碍,可能根本不值得这么麻烦。
到目前为止,最简单、最通用的解决方案是从 Windows API 调用“打开”对话框。它位于 comdlg32.dll 中,该文件在您可能瞄准的每个 Windows 版本上都可用,并且不不对 comdlg32.ocx 施加任何依赖。它还提供比使用 ActiveX 控件更好的性能,因为它不需要将附加模块加载到内存中。
所需的代码也不是很复杂。您需要提供函数
GetOpenFileName
,这会创建“打开”对话框。它采用单个参数,即OPENFILENAME
结构的实例 包含用于初始化对话框的信息,以及接收用户选择的文件的路径。因此,您还需要提供此结构的声明。 VBA 中的代码看起来像这样:您还可以将几个常量作为标志传递来自定义对话框的行为。为了完整起见,这里是完整列表:
为了方便起见,我将整个混乱的内容包装在一个辅助函数中,您可以从 VBA 中调用该函数。它接受您最常需要为打开文件对话框设置的属性作为参数,处理调用 Windows API 本身,然后返回用户所选文件的完整路径或空字符串 (
vbNullString
)如果用户单击“取消”按钮。您可以测试调用代码中的返回值以确定要采取的操作过程。哇,结果很长。您需要将大量声明复制并粘贴到模块中,但您实际需要处理的接口却出奇地简单。以下是如何在代码中实际使用它来显示打开文件对话框并获取文件路径的示例:
编写和测试此解决方案的最长部分实际上是试图找到如何打开VBA 编辑器并在 Access 中编写宏。对于使用主要菜单“粘贴”和“保存”的人来说,功能区可能是一项伟大的发明,但这是多么痛苦的事情。我花了一整天的时间使用软件,但我仍然找不到东西。 [/咆哮]
First of all, the "CommonDialog Class" doesn't even appear to work on a 32-bit version of Office. It gives the same OleDb error. As one of the commenters points out, this isn't the control you should be using. And while there might be another ActiveX control you could use, there's really no guarantee that it will be available on every machine that you want to deploy your database on. My dev box has Visual Studio 6, VS 2008, and VS 2010 on it, in addition to Office and other programs, all of which provide ActiveX DLLs that a typical user could not be expected to have. Additionally, many of these libraries are not redistributable, or pose unique installation hurdles that may simply not be worth the trouble.
By far, the simplest, most universal solution is to call the Open dialog from the Windows API. It's located in comdlg32.dll, which is available on every version of Windows you could possibly be targeting, and doesn't impose any dependencies on comdlg32.ocx. It also provides better performance than using an ActiveX control because it doesn't require an additional module to be loaded into memory.
The code that is required isn't very complicated either. You need to provide a declaration for the function
GetOpenFileName
, which creates the Open dialog box. It takes a single parameter, an instance of theOPENFILENAME
structure that contains information used to initialize the dialog box, as well as receiving the path to the file selected by the user. So you'll also need to provide a declaration of this structure. The code in VBA would look something like this:There are also a couple of constants you can pass as flags to customize the dialog's behavior. For completeness, here's the full list:
And for convenience, I've wrapped this whole mess inside of a helper function that you can call from within VBA. It accepts as parameters the properties you will most commonly need to set for the open file dialog, handles calling the Windows API itself, and then returns either the full path to the file selected by the user, or an empty string (
vbNullString
) if the user clicked the Cancel button. You can test the return value in the calling code to determine which course of action to take.Wow that ended up being long. There are a lot of declarations you'll need to copy and paste into a module, but the interface you actually have to deal with is surprisingly simple. Here's a sample of how you might actually use this in your code to show the open file dialog and get the path to a file:
The longest part of writing and testing this solution was actually trying to find how to open the VBA editor and write a macro in Access. The Ribbon might be a great invention for people who use the menu primary for "Paste" and "Save", but what a pain. I spend all day using software, and I still can't find stuff. [/rant]
我错过了 64 位访问详细信息。您不太可能应该运行它,但如果您运行它,这里有一篇文章供您考虑,其中解释了如何更改 API 调用才能工作 - 您必须使用新的长指针数据类型:
Office 2010 32 位和 64 位版本之间的兼容性
如果您相应地更改 API 代码,它应该可以在 64 位 Access 上正常工作。
但您确实应该问一下为什么要使用 64 位 Access。 MS 实际上根本不建议任何人使用 64 位 Office,除非他们有需要它的具体原因(例如需要使用它提供的额外内存,特别是对于复杂的 Excel 电子表格模型之类的东西)。 Access 绝对不是从转换到 64 位中受益匪浅的应用程序之一。
详细讨论主题:
简而言之,大多数人不应该运行 64 位 Office,这正是您遇到的原因 - 它会导致外部依赖于 32 位组件和 API 的遗留代码失败。
I missed the 64-bit Access detail. It's very unlikely that you should be running it, but if you are, here is an article for your consideration that explains how you have to alter your API call to work -- you have to use the new long pointer data type:
Compatibility Between the 32-bit and 64-bit Versions of Office 2010
If you alter the API code accordingly, it should work fine on 64-bit Access.
But you should really ask why you're using 64-bit Access. It's really not at all recommended by MS that anyone use 64-bit Office unless they have specific reasons why they need it (such as needing to use the extra memory it provides, particularly for things like complex Excel spreadsheet models). Access is definitely not one of the apps that benefits much from the conversion to 64-bit.
Detailed discussion of the subject:
In short, most people shouldn't be running 64-bit Office, precisely for the reason you encountered -- it causes legacy code with outside dependencies on 32-bit components and APIs to fail.
我刚刚在 64 位版本的 Excel 2013 中努力解决此问题。
结合...
LongPtr
数据类型 (hwndOwner
传递给GetOpenFileNameA
的OPENFILENAME
结构中的 code>、hInstance
、lpfnHook
)Len
在获取OPENFILENAME
结构的大小时(如 Max Albanese 提到的),使用LenB
函数使用code> 函数
...成功了,这要归功于此处记录的指导:
https://gpgonaccess。 blogspot.co.uk/2010/03/work-in-progress-and-64-bit-vba.html
I've just been wrestling with resolving this issue in a 64-bit version of Excel 2013.
A combination of...
LongPtr
data type for 3 of the items (hwndOwner
,hInstance
,lpfnHook
) in theOPENFILENAME
structure passed toGetOpenFileNameA
Len
function with theLenB
function when obtaining the size of theOPENFILENAME
structure (as mentioned by Max Albanese)...did the trick, thanks to guidance documented here:
https://gpgonaccess.blogspot.co.uk/2010/03/work-in-progress-and-64-bit-vba.html