ronggang 的方法
'************************************************
'** 函数名称: ShowForm
'** 函数功能: 根据窗体名称来显示/加载窗体
'** 参数说明:
'** strFormName 窗体名称
'** 函数返回:
'** Boolean 类型
'** True 显示/加载成功
'** False 显示/加载失败
'** 参考实例:
'** Call ShowForm("frmUser")
'************************************************
Private Function ShowForm(ByVal strFormName As String) As Boolean
Dim frmTemp As Form
Dim strTemp As String
On Error GoTo LocalErr
'********** 判断窗体是否已经打开 ********** 1
For Each frmTemp In Forms
strTemp = frmTemp.Name
If UCase(strFormName) = UCase(strTemp) Then
frmTemp.Show
frmTemp.ZOrder
ShowForm = True
Exit Function
End If
Next
'****************************************** 1
'// 增加窗体到“窗体集合”中
Set frmTemp = Forms.Add(strFormName)
'// 显示窗体
frmTemp.Show
frmTemp.ZOrder
ShowForm = True
Exit Function
LocalErr:
'// 当 strFormName 这个名称在当前工程中不存在时,会产生一个错误(424:要求对象)
Err.Clear
ShowForm = False
End Function
Private Declare Function EbExecuteLine Lib "vba6.dll" (ByVal pStringToExec As Long, ByVal Unknownn1 As Long, ByVal Unknownn2 As Long, ByVal fCheckOnly As Long) As Long
Private Function ShowForm(ByVal frm As String) As String
EbExecuteLine StrPtr(frm & ".SHOW"), 0, 0, 0
End Function
'例子
Private Sub Command1_Click()
Dim S As String
'S = "form1"
S = "form2"
ShowForm S
End Sub