Application.run doesn't work with module

2019-06-25 18:41发布

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.

1条回答
一纸荒年 Trace。
2楼-- · 2019-06-25 19:34

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.

查看更多
登录 后发表回答