访问 VBA - 相对文件引用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1389705/
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
Access VBA - relative file references
提问by MT.
In have built a couple of mda library files which I am then referencing from my main Access application (i.e. using Tools -> References from within the IDE).
我已经构建了几个 mda 库文件,然后我从我的主 Access 应用程序中引用这些文件(即在 IDE 中使用工具 -> 引用)。
Is there a way that these references can be made relative rather than absolute. The reason I am asking is so that it would make it easy to set-up on the user's computer if all three files (main application and two mda files) could simply be placed in any directory and work without having to change the references...
有没有办法可以使这些引用相对而不是绝对。我问的原因是,如果所有三个文件(主应用程序和两个 mda 文件)都可以简单地放在任何目录中并且无需更改引用就可以工作,那么它可以很容易地在用户的计算机上进行设置。 .
Thanks
谢谢
回答by Tony Toews
Why not just place the three MDEs in the same folder on the target system? Access should find the MDE references just fine.
为什么不将三个 MDE 放在目标系统上的同一个文件夹中?Access 应该可以很好地找到 MDE 引用。
Or are you using the add-in logic with the USysRegInfo table? You don't really need to do that with your own add-ins. Just with developer type add-ins such as Rick Fisher's Find and Replace.
或者您是否使用带有 USysRegInfo 表的加载项逻辑?您实际上不需要使用自己的加载项来执行此操作。只需使用开发人员类型的加载项,例如 Rick Fisher 的 Find and Replace。
If this isn't working for you then tell us what error messages or symptoms.
如果这对您不起作用,请告诉我们什么错误消息或症状。
回答by Russ Cam
To get the file path for the access application
获取访问应用程序的文件路径
CurrentProject.Path & "\"
Then just add the other files into the same directory and get them by name. i.e.
然后只需将其他文件添加到同一目录中并按名称获取它们。IE
Dim filepath As String
filepath = CurrentProject.Path & "\name_of_file.mda"
回答by Mike
You can add VBA references through VBA itself.
您可以通过 VBA 本身添加 VBA 引用。
Dim sFilename As String
sFilename = CurrentProject.Path & "\" & whatever.mda
Application.References.AddFromFile sFilename
Just put that in your AutoExec and that reference ought to be available for everything. Of course, you'll have to check if the reference already exists before adding it, otherwise you get an error. But that's just a matter of looping through Application.References.
只需将它放在您的 AutoExec 中,该参考应该可用于所有内容。当然,您必须在添加引用之前检查该引用是否已存在,否则会出现错误。但这只是遍历 Application.References 的问题。