公共子 [英] Public sub

查看:76
本文介绍了公共子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个更大的问题,但让我们从这个问题开始...


我创建了一个新的模块,有一个公共子。

和当我尝试从表单中执行此子程序时,它给出了一个错误:


编译错误:sub或函数未定义


thats 公共的概念所以它将在所有形式上定义不是吗?


任何想法为什么它不起作用?

I have a bigger question but lets start with this problam...

I have created a new moudle, with a public sub.
and when I try to excute this sub from a form it gives me an error of:

compile error: sub or function not defined

thats the idea of ''public'' so it will be defined on all forms isn''t ?

any ideas why it doesn''t work ?

推荐答案


我有一个更大的问题,但让我们从这个问题开始......


我有创建了一个新的模块,带有一个公共子。

当我尝试从表单中执行此子时它给了我一个错误:


编译错误:sub或函数未定义


表示公共的概念所以它将在所有表格中定义不是吗?


任何想法为什么它不起作用?
I have a bigger question but lets start with this problam...

I have created a new moudle, with a public sub.
and when I try to excute this sub from a form it gives me an error of:

compile error: sub or function not defined

thats the idea of ''public'' so it will be defined on all forms isn''t ?

any ideas why it doesn''t work ?



zivon。


信不信由你,可以调用在代码模块中声明为public的function / sub在任何模块中。 ;)

如果您提供其他信息,那么它在您的案例中不起作用的原因可能会更清楚。

Hi, zivon.

Believe it or not, but function/sub declared as public in code module may be invoked in any module. ;)
The reason why it is not working in your case may be more clear if you provide additional information.


抱歉,但是为了公共子/ form要从数据库中的任何表单调用,它必须放在标准模块中,而不是放在表单后面的代码模块中!从对象对话框中,模块 - 新建,然后输入子代码。当提示命名模块时,将其命名为除了与子/函数相同的名称


Linq ; 0)>
Sorry, but in order for a Public sub/form to be called from any form in a database, it has to be placed in a standard module, not in a code module behind a form! From the object dialog box, Modules - New and enter your code for the sub. When prompted to name the module, name it anything except the same name as the sub/function!

Linq ;0)>


这就是我的想法,但它不起作用:\


这里是我正在尝试的< br $>
a moudle称为''电子邮件''


公共子测试()

MsgBox(这是测试)<
结束Sub


表格:


私人子测试_点击()

测试

End Sub
thats what I was thinking, but it doesn''t work : \

here is what I''m trying
a moudle called ''email''

Public Sub test()
MsgBox ("this is a test")
End Sub

on the form:

Private Sub test_Click()
test
End Sub


这篇关于公共子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆