Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 8 of 8

Thread: Activecontrol in a Multipage

  1. #1
    New Member
    Join Date
    Apr 2002
    Posts
    9
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi

    I need to perform some checks in textboxes contained in a multipage. I'm trying to reference currently active control by using this command:

    ME.ACTIVECONTROL.NAME

    But, despite the textboxes have the focus, the command always return Mutlipage1 as the activecontrol.

    How can I reference the textbox directly as the active control?

    Tks

  2. #2
    Rest in Peace
    Join Date
    Feb 2002
    Posts
    1,582
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi

    This should work

    Me.MultiPage1.Pages(Me.MultiPage1.Value).ActiveControl.Name

  3. #3
    New Member
    Join Date
    Apr 2002
    Posts
    9
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Whatif this combobox is inside a frame that is inside a page that is inside a multipage

    Tks a lot

  4. #4
    Rest in Peace
    Join Date
    Feb 2002
    Posts
    1,582
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Maybe:

    Me.MultiPage1.Pages(Me.MultiPage1.Value).Frame1.ActiveControl.Name

  5. #5
    New Member
    Join Date
    Apr 2002
    Posts
    9
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Yeah this works, but the point is that I have may frames and I'd like to refer to objects inside all these different frames.

    Tks Dave

  6. #6
    New Member
    Join Date
    Oct 2005
    Posts
    1
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Code:
      Dim LastFocussedControl As Control
      
      'This allows a control to be inside a frame inside a multipage
      'For nested multipages use a whileloop for example, I'm sure you can workout
      Set LastFocussedControl = ActiveControl
      If (Left(LastFocussedControl.Name, Len("Multipage")) = "MultiPage") Then
        Set LastFocussedControl = LastFocussedControl.Pages(LastFocussedControl.Value).ActiveControl
      End If
      If (Left(LastFocussedControl.Name, Len("Frame")) = "Frame") Then
        Set LastFocussedControl = LastFocussedControl.ActiveControl
      End If

  7. #7
    New Member
    Join Date
    Jan 2012
    Posts
    2
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Activecontrol in a Multipage

    The way I find which control is active on a multipage is the following code:
    This does not handle for Multipages in Frames or vice-versa, but should could be easily augmented for that scenerio

    Dim sControlName As String
    Dim iMulitPageSelect As Integer

    If TypeOf Me.ActiveControl Is Frame Then
    ' If active control is in a frame then give sControlName that control's name
    sControlName = Me.Controls(Me.ActiveControl.Name).ActiveControl.Name
    ElseIf TypeOf Me.ActiveControl Is MultiPage Then
    'Find Current page of MultiPage
    'use the page index value to find active control name
    iMulitPageSelect = Me.Controls(Me.ActiveControl.Name).Value
    sControlName = Me.ActiveControl.Pages(iMulitPageSelect).ActiveControl.Name
    Else
    'if active control is neither in a frame or Multipage
    sControlName = Me.ActiveControl.Name
    End If

    -Landon

  8. #8
    MrExcel MVP mikerickson's Avatar
    Join Date
    Jan 2007
    Location
    Davis CA
    Posts
    21,783
    Post Thanks / Like
    Mentioned
    8 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Activecontrol in a Multipage

    This will drill down past the Frames and the MultiPages to give you the control that is active.

    Code:
    Function RootActiveControl(Optional Container As Object) As Object
        Dim tActiveControl As Object
        If Container Is Nothing Then Set Container = Me
    
        Set tActiveControl = Container.ActiveControl
    
        Select Case TypeName(tActiveControl)
            Case "Frame"
                Set RootActiveControl = RootActiveControl(tActiveControl)
            Case "MultiPage"
                With tActiveControl
                    Set RootActiveControl = RootActiveControl(.Pages(.Value))
                End With
            Case Else
                Set RootActiveControl = tActiveControl
        End Select
    End Function

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •