Function test(frm As Form) As String
On Error GoTo err:
test = frm.Parent.Name
err_exit:
Exit Function
err:
test = "无父对象"
Resume err_exit:
End Function
Private Sub 主窗体测试_Click()
MsgBox test(Me.Form)
End Sub
Private Sub 子窗体测试_Click()
MsgBox test(Me.子窗体.Form)
End Sub 作者: zhengjialon 时间: 2011-11-30 12:22
谢谢! 看来只能通过判断是否有错误的方法了{:soso_e179:}作者: t小宝 时间: 2011-11-30 12:22
主窗体还是父窗体?作者: zhengjialon 时间: 2011-11-30 12:26
父窗体,我说错了{:soso_e113:}作者: t小宝 时间: 2011-11-30 12:54
不判断错误也可以,用API:
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Sub Command0_Click()
Dim lpClassName As String * 256
If Left$(lpClassName, GetClassName(GetParent(Me.hwnd), lpClassName, 256)) = "OFormsub" Then
MsgBox "有父窗体"
Else
MsgBox "没有父窗体"
End If
End Sub 作者: zhengjialon 时间: 2011-12-1 09:08
谢谢小宝,收藏了