+ Reply to Thread
Results 1 to 6 of 6

Finding out which box on a user form has focus

Hybrid View

duckboy1981 Finding out which box on a... 02-13-2009, 12:51 PM
royUK Re: Finding out which box on... 02-13-2009, 01:07 PM
duckboy1981 Re: Finding out which box on... 02-16-2009, 05:21 AM
duckboy1981 Re: Finding out which box on... 02-16-2009, 05:44 AM
royUK Re: Finding out which box on... 02-16-2009, 06:14 AM
duckboy1981 Re: Finding out which box on... 02-16-2009, 06:25 AM
  1. #1
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Finding out which box on a user form has focus

    Does anybody know of a way of getting the name of the text box that currently has focus on a user form?

    Thanks.
    Last edited by duckboy1981; 02-16-2009 at 06:22 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Finding out which box on a user form has focus

    How do you want to use this/
    MsgBox ActiveControl.Name
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Re: Finding out which box on a user form has focus

    Hi Roy,

    Thanks for that. I need check the input of 10 textbox's against certain criteria and then, if any have errors, display a message and redisplay the form with focus in the first field that had an error. The rest is working, just the last bit.

    Thanks

  4. #4
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Re: Finding out which box on a user form has focus

    I've sorted it, managed to bodge a way of doing it using the code you gave. Thanks for your help.

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Finding out which box on a user form has focus

    You don't need that cose, if you say exactly what you need you can either loop through the textboxes or use individual textbox exit events.

  6. #6
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Re: Finding out which box on a user form has focus

    Further refined and as it happens that code is not used now. Another guy helped me with a chunk of this but it works a treat now, does exactly what the 'powers that be' want it to do, hopefully in the most efficient way aswell!

    Thanks

        Do While Continue = False
            Error = ""
            FirstError = 0
            For count = 1 To 10
                With Me.Controls("txtText" & count)
                    If Len(.Value) > 5 Then
                        If Error = "" Then
                            Error = "Text field " & count
                        Else
                            Error = Error & vbCrLf & "Text field " & count
                        End If
                        If FirstError = 0 Then
                            FirstError = count
                        End If
                    End If
                End With
            Next count
            If Error <> "" Then
                MsgBox "The text to be displayed on the Intranet cannot be longer than 50 characters." & vbCrLf & "Please edit the following fields" & vbCrLf & vbCrLf & Error, vbInformation, "Invalid Field Length"
                Me.Controls("txtText" & FirstError).SetFocus
                Exit Sub
            Else: Continue = True
            End If
        Loop

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1