Results 1 to 6 of 6
  1. #1
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Referencing Control with Focus (A2K SR1)

    A form, Form1, has four multiselect listbox controls, listbox1, listbox2, listbox3 and listbox4. Each of the listboxes after update event triggers similar code. Rather then re-write the similar code in each after update event for each listbox, I want to trigger the code from a module. (Saves on typing).

    The question is this. In the module I need to reference which listbox has the focus when the module is called. Is there an easy way to obtain the name of the control on the form that has the current focus when the module was called?
    Regards,

    Gary
    (It's been a while!)

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Referencing Control with Focus (A2K SR1)

    Hello Gary,

    Screen.ActiveControl (or Me.ActiveControl) is the control object that has the focus; Screen.ActiveControl.Name (or Me.ActiveControl.Name) is the name of that control.

  3. #3
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Referencing Control with Focus (A2K SR1)

    Gary
    Hans suggested Screen.ActiveControl rather than Forms]![Form1]!activecontrol.
    This is a stab in the dark, but who knows.

  4. #4
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Referencing Control with Focus (A2K SR1)

    Hey Pat.

    Thanks for setting me straight. You and Hans are both right. <img src=/S/bwaaah.gif border=0 alt=bwaaah width=123 height=15> - my reaction since I cant read correctly.
    Regards,

    Gary
    (It's been a while!)

  5. #5
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Referencing Control with Focus (A2K SR1)

    Hey Hans,

    I am not out of the dark yet.

    I tried what you suggested and several variations but can't get it right.

    Basically, the module is referencing a form. For example, textbox1 on Form1 is referenced from the module as
    [Forms]![Form1]![Textbox1] - this works no problem.

    But I can't get the activecontrol.name format correct for referencing the active control from the module.
    [Forms]![Form1]!activecontrol.name or [Forms]![Form1]!screen.activecontrol.name does not work.

    Any ideas? I have already used a work around but would rather have the coding work without the workaround.

    As always, thanks for the help.
    Regards,

    Gary
    (It's been a while!)

  6. #6
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Referencing Control with Focus (A2K SR1)

    Thanks Hans,

    Had I read your response correctly, it would have worked. Thanks to Pat for pointing that out.

    Thanks as always for the help. Its Friday afternoon and my brains have gone <img src=/S/cooked.gif border=0 alt=cooked width=50 height=46> - Time to go home.
    Regards,

    Gary
    (It's been a while!)

Posting Permissions

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