我有两个模块.在一个模块中,我想间接运行另一个模块中的一个子模块.据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不适用于模块
发布评论