?
Solved

Execute code, only on a textbox

Posted on 2011-04-27
1
Medium Priority
?
234 Views
Last Modified: 2012-05-11
I have the following code that is working fine:

Private Sub WebBrowser1_LostFocus()
    On Error Resume Next
    Dim ac As Control
    Set ac = Me.ActiveControl
    If Not ac = False Then
        Me.SetFocus
        If Not ac Is Nothing Then
            If ac.Enabled And ac.Visible Then
                ac.SetFocus
            End If
        End If
    End If
    On Error GoTo 0
End Sub

I'd like the code to fire only if the ActiveControl is a textbox.  Any ideas?
0
Comment
Question by:hrolsons
1 Comment
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 35479518
How about:
Private Sub WebBrowser1_LostFocus()
    On Error Resume Next
    Dim ac As Control
    Set ac = Me.ActiveControl
    If Not ac = False And TypeOf ac Is TextBox  Then
        Me.SetFocus
        If Not ac Is Nothing Then
            If ac.Enabled And ac.Visible Then
                ac.SetFocus
            End If
        End If
    End If
    On Error GoTo 0
End Sub

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question