Results 1 to 6 of 6

Thread: ActiveControl within a frame on a form.
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular Darren Bartrup's Avatar
    Join Date
    Mar 2006
    Location
    Nottingham (UK)
    Posts
    1,258
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default ActiveControl within a frame on a form.

    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 'TakeFocus*******' option to False so that the user can select an email and press the button.
    The ActiveControl points to the frame and not the selected textbox though. How do I achieve this?

    Any help is greatly appreciated as usual!

  2. #2
    Board Regular Darren Bartrup's Avatar
    Join Date
    Mar 2006
    Location
    Nottingham (UK)
    Posts
    1,258
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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?

  3. #3
    MrExcel MVP erik.van.geit's Avatar
    Join Date
    Feb 2003
    Location
    Belgium 3272 Testelt
    Posts
    17,832
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi,

    once my struggle with this was hard
    try this
    Code:
    MsgBox Me.ActiveControl.ActiveControl.Text
    kind regards,
    Erik
    I love Jesus

    email Erik

    founder of DRAFT

    my free Addins
    Table-It download & info
    Formula Translator 04

  4. #4
    Board Regular Darren Bartrup's Avatar
    Join Date
    Mar 2006
    Location
    Nottingham (UK)
    Posts
    1,258
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    That seems to do the trick.

    Thanks Erik!

  5. #5
    MrExcel MVP erik.van.geit's Avatar
    Join Date
    Feb 2003
    Location
    Belgium 3272 Testelt
    Posts
    17,832
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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 'TakeFocus*******' option

    thanks for asking this
    I love Jesus

    email Erik

    founder of DRAFT

    my free Addins
    Table-It download & info
    Formula Translator 04

  6. #6
    Board Regular Darren Bartrup's Avatar
    Join Date
    Mar 2006
    Location
    Nottingham (UK)
    Posts
    1,258
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: ActiveControl within a frame on a form.

    That was handy. Google sent me to the same solution ten years after I first asked.
    Using Office 2003 & 2010,

    I'm 1 of the 10 people that don't understand binary. Guess that means the other 1001 do.

    No answer to your post?
    Get someone to read it - does it make sense or does it sound like gibberish?

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
  •