<form id="hbx9t"></form>

<noframes id="hbx9t">

    <em id="hbx9t"><span id="hbx9t"></span></em>

        <noframes id="hbx9t"><address id="hbx9t"><th id="hbx9t"><progress id="hbx9t"></progress></th></address>
        office交流網--QQ交流群號

        Access培訓群:792054000         Excel免費交流群群:686050929          Outlook交流群:221378704    

        Word交流群:218156588             PPT交流群:324131555

        如何獲取當前激活的子窗體控件的名稱

        2021-01-03 10:03:00
        zstmtony
        原創
        15647
         '如果焦點在主窗體里的子窗體控件里的子窗體的控件上,則以下代碼
        MsgBox Screen.ActiveControl.Name  '當前獲得焦點的子窗體控件里面的控件的名稱
        MsgBox Screen.ActiveForm.Name  '當前激活的窗體的名稱 (主窗體)
        MsgBox Screen.ActiveControl.Parent.Name  '當前激活的子窗體的名稱 (子窗體)

        MsgBox Screen.ActiveControl.Parent.Parent.Name '當前激活的子窗體的父容器名稱 (主窗體)



        Dim ctr As Control
        For Each ctr In Screen.ActiveControl.Parent.Parent
        If TypeOf ctr Is SubForm Then
        MsgBox ctr.Name '子窗體控件的名稱  (非子窗體窗體)
        End If

        Next




        更簡單的方法 獲取當前激活的子窗體控件的名稱


        Dim ctr As Control
        For Each ctr In Screen.ActiveForm.Controls
        If TypeOf ctr Is SubForm Then
        MsgBox ctr.Name '子窗體控件的名稱

        '如果希望判斷 是否焦點所在的子窗體,可以再判斷 if ctr.Form.Name=Screen.ActiveControl.Parent.Name Then  相等就是激活的子窗體
        End If

        Next

        分享