Application.run不适用于模块

编程入门 行业动态 更新时间:2024-10-28 02:36:13
本文介绍了Application.run不适用于模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有两个模块.在一个模块中,我想间接运行另一个模块中的一个子模块.据MS和许多在线资源称,这应该可行-但事实并非如此.可能是什么问题?

'Module: "Helpers" Public Sub ubTest() MsgBox "ubTest is called" End Sub 'Another Module -> I also tried this from a form and a class... Public Sub test() Dim s As String Helpers.ubTest 'works s = "ubTest" Application.Run s 'works s = "Helpers.ubTest" Application.Run s 'doesn't work End Sub

(显然,这是一个测试-在实际的应用程序中,我将有多个模块,并且将不会始终控制过程名称-因此,我必须使用模块前缀)

我试图/反编译并压缩数据库-那里也没有运气.

解决方案

访问 Application.Run方法帮助主题对 Name 参数进行了说明:

'如果要在另一个数据库中调用过程,请使用项目名称和过程名称,并用点号分隔,形式为"projectname.procedurename".'

因此,我认为当您提供"modulename.procedurename"(即"Helpers.ubTest" )时,Access会认为您的 modulename 是VBA项目的名称.由于找不到程序 Helpers ,因此抛出错误#2517,"...找不到过程'Helpers.ubTest.'

不幸的是,我找不到用Application.Run做我想做的事情的方法.我希望"projectname.modulename.procedurename"将起作用,但这也触发了2517错误.

I have two modules. In one module I want to run a sub from the other module indirectly. According to MS and a multitude of online ressources this should work - but it doesn't. What could be the problem?

'Module: "Helpers" Public Sub ubTest() MsgBox "ubTest is called" End Sub 'Another Module -> I also tried this from a form and a class... Public Sub test() Dim s As String Helpers.ubTest 'works s = "ubTest" Application.Run s 'works s = "Helpers.ubTest" Application.Run s 'doesn't work End Sub

(Obviously this is a test - in the real application I will have multiple modules and will not always have control over the procedure names - so I have to use the module-prefix)

I tried to /decompile and compact the database - no luck there either.

解决方案

The Access Application.Run Method help topic says this about the Name parameter:

'If you are calling a procedure in another database use the project name and the procedure name separated by a dot in the form: "projectname.procedurename".'

So I think when you supply "modulename.procedurename" (ie "Helpers.ubTest"), Access thinks your modulename is the name of a VBA project. Since it can't find a project named Helpers, it throws error #2517, " ... can't find the procedure 'Helpers.ubTest.'"

Unfortunately, I can't find a way to do what I think you want with Application.Run. I hoped "projectname.modulename.procedurename" would work, but that also triggered the 2517 error.

更多推荐

Application.run不适用于模块

本文发布于:2023-06-04 21:18:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/505247.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模块   不适用于   Application   run

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!