Activecontrol in a Multipage

rgjabali

New Member
Joined
Apr 9, 2002
Messages
9
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
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,397
Messages
6,119,273
Members
448,883
Latest member
fyfe54

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top