Does anybody know of a way of getting the name of the text box that currently has focus on a user form?
Thanks.
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.
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
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
I've sorted it, managed to bodge a way of doing it using the code you gave. Thanks for your help.
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.
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks