【发布时间】:2016-04-20 21:58:22
【问题描述】:
Modules() 集合包含所有打开的模块,包括位于表单后面的模块。但我不知道如何引用表单后面的模块。在下面的代码中(来自即时窗格),命名约定是以“M_”开头的对象是独立模块,而以“F_”开头的对象是表单。
从即时窗格中:
'Proving that the method works for standalone modules:
debug.print Modules("M_Test").Name
M_Test
' Proving I am spelling the name of the form correctly:
debug.Print currentproject.AllForms("F_Inserts").Name
F_Inserts
' Proving the form is open (so it appears in Modules() collection)
debug.Print currentproject.AllForms("F_Inserts").IsLoaded
True
很好。尝试访问表单后面的模块 - 不要忘记,所有表单的模块都以“Form_”为前缀:
debug.Print Modules("Form_F_Inserts").Name
debug.Print Modules("F_Inserts").Name
两次都导致运行时错误 7961 -“找不到宏表达式或 Visual Basic 代码中引用的模块 'Form_F_Inserts'”。 现在几乎和往常一样,“帮助”按钮坏了,把我带到“无法服务请求”错误页面 (https://msdn.microsoft.com/Areas/Epx/Content/500.aspx?aspxerrorpath=/query/dev11.query)。
该例程的目的是为每个表单模块获取.CountOfLines。以下是全部内容:
Dim lOut As String, lVariant As Variant, lInt As Integer, lBool As Boolean
lInt=0
For Each lVariant In CurrentProject.AllForms
lBool = lVariant.IsLoaded 'If not loaded, we open it & close it after
If Not lBool Then DoCmd.OpenForm lVariant.Name, acDesign, WindowMode:=acHidden
If Forms(lVariant.Name).HasModule Then lInt = lInt + Modules("Form_" & lVariant.Name).CountOfLines
If Not lBool Then DoCmd.Close acForm, lVariant.Name, acSaveNo
Next
有什么想法吗?
【问题讨论】:
标签: ms-access vba ms-access-2013