vba 从 Access 2010 中的函数调用子

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13463151/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 18:33:04  来源:igfitidea点击:

Call a sub from a function in Access 2010

vbams-accessms-access-2010

提问by GRY

My MS Access application has a subroutine which fires after I update one control on a form.

我的 MS Access 应用程序有一个子例程,它会在我更新表单上的一个控件后触发。

Public Sub cboCrew_AfterUpdate()
    ...do some work...
End Sub

I would like to call this same sub from a function I have defined in Module1

我想从我在 Module1 中定义的函数调用这个相同的 sub

Function my_function()
     Call cboCrew_AfterUpdate
End Function

This code throws the error: "Compile Error Sub or Function not defined"

此代码抛出错误:“编译错误子或函数未定义”

I suspect that the problem is that I am not being specific enough, in my call to the sub. Do I need to reference the sub with "some_modulte_name.sub_name"? Can anyone tell me what I am missing?

我怀疑问题在于我在给 sub 的调用中不够具体。我需要引用 sub"some_modulte_name.sub_name"吗?谁能告诉我我错过了什么?

采纳答案by Fionnuala

Set this up the other way around...

反过来设置这个...

Public Sub cboCrew_AfterUpdate()
    My_Function
End Sub

Function my_function(frm As Form)
     ''Do stuff
End Function

Re comment

重新评论

Public Sub cboCrew_AfterUpdate()
    My_Function Me 
End Sub

Function my_function(frm As Form)
     MsgBox frm.Name
End Function

Sub AnotherSub()
   My_Function Forms!AFormName
End Sub