|
本帖最后由 layaman_999 于 2012-6-15 18:01 编辑
函数模块
Function OpenF(FormName As String, Optional View = acNormal, Optional FilterName = Null, Optional WhereCondition = Null, _
Optional DataMode = acFormPropertySettings, Optional WindowMode = acWindowNormal, Optional OpenArgs = Null) As Form
On Error GoTo cuowu
DoCmd.OpenForm FormName, View, FilterName, WhereCondition, DataMode, WindowMode, OpenArgs
If CurrentProject.AllForms(FormName).IsLoaded = True Then
Set OpenF = Forms(FormName)
Else
Set OpenF = Nothing
End If
Exit Function
cuowu:
Set OpenF = Nothing
MsgBox "对象[" & FormName & "]无法加载!"
End Function
===================
调用方法1(直接给值到窗体变量):
Dim Frm As Form
Set Frm = OpenF("窗体3")
If Frm Is Nothing Then Exit Sub
Frm.Caption = "哈哈哈" '设置窗体的其他属性
=============
调用方法2(窗体无法加载则不执行后面的代码):
if OpenF("窗体3") Is Nothing Then Exit Sub
==============
调用方法3(简单的)
call OpenF("窗体3")
================
注意:以上方法只能在代码中使用,如果在按钮或者其他控件的事件属性中直接写 =OpenF("窗体3")则会出错,那就要再建立一个返回String的函数:Function OpenFA(.......) As String,里面的代码做点小小修改,具体调整非常简单,就不再啰嗦了==================
写成函数可极大的简化代码,并且减少出错的几率)
|
|