Please help with this question on using a variable to assign property value

Posted on 2009-12-19
Last Modified: 2012-05-08
My code is:
   'bacto = (Me.ActiveControl.Name)
the "bacto.setfocus instruction does not work because it is taking "bacto" as the control name rather than the variable that "bacto" refers to .
How do I fix that so I get the control "bacto" refers to, to have focus?
Question by:rbend
    LVL 59

    Accepted Solution

    Hello rbend,

    Try me.controls(bacto).setfocus


    LVL 85

    Expert Comment

    by:Mike Tomlinson
    The bigger question is why are you using the Name() property instead of the Control itself?

    Why not?

        Dim ctl As Control
        Set ctl = Me.ActiveControl

    Then later:


    You could still use the Name property via "ctl":

        Dim ctlName As String
        ctlName = ctl.Name

    Author Comment

    sorry..didn't see the second solution before I awarded to first.
    Next time.
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    No problem.  Chris gave a great solution to your problem.  =)
    LVL 59

    Expert Comment

    by:Chris Bottomley
    Glad to help


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    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…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    794 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now