Results 1 to 3 of 3

Thread: Focus

  1. #1
    Join Date
    May 2003
    Posts
    144

    Unanswered: Focus

    Help. Is there a way to find out which field on the form currently has the focus through VBA?

    Thanks

    SHK

  2. #2
    Join Date
    Sep 2001
    Location
    Chicago, Illinois, USA
    Posts
    601
    Screen.ActiveForm

  3. #3
    Join Date
    Nov 2003
    Posts
    1,487
    The code to do this is simple....the hard part is "when do you fire it". To test the one liner code below, create a unbound TextBox on your Form and name it "HasFocus". Next, set the Timer Interval property for your Form to 1.

    Now in the On Timer event of your Form enter this line of code:

    Me.HasFocus = Screen.ActiveForm.ActiveControl.Name

    When run, your new textbox will display the name of the control which has focus.

    Now....I don't recommend using the timer for this. It is used here so as to show you what the code can do. How and where you use the code is up to you.


Posting Permissions

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