ActiveControl within a frame on a form.

Darren Bartrup

Well-known Member
Joined
Mar 13, 2006
Messages
1,296
Office Version
  1. 365
Platform
  1. Windows
ok, here's the problem (and I really hope I explain it clearly):

I have a form which contains a number of textboxes (added at runtime). Each textbox contains between zero and three email addressess seperated by a ';'.
When a textbox is double-clicked a new form appears which shows each email address in a seperate textbox within a frame (again, these are added at runtime).
I put the textboxes within a frame so that a scrollbar can be added if more textboxes need to be added than the form can hold.

Now here's the problem:
Beneath the frame I've put a command button which eventually will allow the user to remove email addressess from the list.
I've set the 'TakeFocusOnClick' option to False so that the user can select an email and press the button.
:eek: The ActiveControl points to the frame and not the selected textbox though. How do I achieve this? :eek:

Any help is greatly appreciated as usual!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I've found a kind of solution, though I'm not sure if it's foolproof or not:
Code:
Private Sub cmdRemove_Click()

    Dim ctrl    As Control
    
    For Each ctrl In Me.Controls
        If Left(ctrl.Name, 5) = "Email" Then
            On Error GoTo InvalidControl
            If ctrl.CurTargetY = 105 Then
                MsgBox ctrl.Value
            End If
        End If
ResumeControls:
        On Error GoTo 0
    Next ctrl

Exit Sub

InvalidControl:
    Resume ResumeControls

End Sub
It seems the CurTargetY value returns 105 if the control is active. Anyone know what the CurTargetY property is all about? :biggrin:
 
Upvote 0
Hi,

once my struggle with this was hard
try this
Code:
MsgBox Me.ActiveControl.ActiveControl.Text

kind regards,
Erik
 
Upvote 0
Solution
you're welcome!!

you pointed me to two things I've never used
1. within a frame so that a scrollbar can be added
2. set the 'TakeFocusOnClick' option

thanks for asking this :)
 
Upvote 0
That was handy. Google sent me to the same solution ten years after I first asked. :)
 
Upvote 0

Forum statistics

Threads
1,213,524
Messages
6,114,117
Members
448,549
Latest member
brianhfield

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