+ Reply to Thread
Results 1 to 16 of 16

GotFocus LostFocus

  1. #1
    Forum Contributor
    Join Date
    06-27-2006
    Posts
    310

    GotFocus LostFocus

    GotFocus and LostFocus for activex controls...

    These two events are straight forward for a commandbutton or a spinbutton , but when does a label or an Image control get or lose focus ?

    when using a message box to test these events
    msgbox "got focus"
    msgbox "lost focus"

    Clicking on a label or an image control doesn't give either of these controls focus.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Curious -- I agree. The click event works ...

  3. #3
    Forum Contributor
    Join Date
    06-27-2006
    Posts
    310
    I can't figure out why GotFocus and LostFocus are available for these controls but never seem to trigger

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello SuitedAces,

    Focus is the ability to receive mouse clicks or keyboard input at any one time. In the Microsoft Windows environment, only one window, form, or control can have this ability at a time. The object that "has the focus" is normally indicated by a highlighted caption or title bar. The focus can be set by the user or by the application.

    These 2 events, GotFocus and LostFous exist in Visual Basic, but not VBA. VBA instead uses the Enter and Exit which are similar. Enter occurs before a control actually receives the focus from a control on the same form. Exit occurs immediately before a control loses the focus to another control on the same form. However, a SetFocus method does exist in VBA for certain controls.

    Sincerely,
    Leith Ross

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Leith,

    I don't see Enter or Exit events for Labels or Image controls; I do see GotFocus and LostFocus as available events in the dropdown for worksheet ActiveX controls, but as Suited Aces says, they don't respond.

    Those events are not listed in the Object Browser for for the MSForms.Image or MSForms.Label objects.

  6. #6
    Forum Contributor
    Join Date
    06-27-2006
    Posts
    310
    That's another question that I have.

    I don't think the events listed in the Object Browser for MSForms refer to activex controls , I'm thinking they apply strictly to controls from the forms toolbar.

    But I could be mistaken.

    It was the next question I was going to ask...where do you find activex controls in the object browser ?

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello SuitedAces,

    Are you embedding the controls on the Worksheet?

    Thanks,
    Leith Ross

  8. #8
    Forum Contributor
    Join Date
    06-27-2006
    Posts
    310
    Yes am and also this one many general question that I am trying to get answered as I begin to use VBA.

    I just seem to encounter a lot of strangeness like this and then my curiousity forces me to ask the questions.

    Because as a beginner here is what it leaves me with otherwise...I am left with no clue as to whether things like this are quirks in VBA or it's my lack of knowledge.

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello SuitedAces,

    When you embed ActiveX objects into the worksheet, the rules change. Not all the object's properties, and methods may be available. This has mainly to do with how the OLE server works. The Forms controls are actually Shapes that are drawn on the worksheet. These are also known as an Owner Drawn Controls, and function very differently from OLE controls. This is a lot to take in even for advanced users, so I hope I didn't confuse you.

    Sincerely,
    Leith Ross

  10. #10
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    One way to find what events are avaliable is to insert a Class module and then type
    Please Login or Register  to view this content.
    In the VB Editor's upper-left drop down, select "tester" and the avaliable events will be listed in the right dropdown.

    You need to be cautious, as
    Please Login or Register  to view this content.
    have the same events, but

    Please Login or Register  to view this content.
    has a different list. And
    Please Login or Register  to view this content.
    doesn't show any events.

    Testing routines like
    Please Login or Register  to view this content.
    help me keep things straight.

    (The "form" in msForms does not refer to the Forms menu. Like Leith Ross said, controls from the Forms menu are shapes and do not have events.

    However, Labels and Images from the Forms menu can be assigned a macro (right click on the image/label, follow the menu), which acts a whole lot like a _Click event.
    Last edited by mikerickson; 10-02-2007 at 08:34 PM.

  11. #11
    Forum Contributor
    Join Date
    06-27-2006
    Posts
    310
    Quote Originally Posted by Leith Ross
    Hello SuitedAces,

    When you embed ActiveX objects into the worksheet, the rules change. Not all the object's properties, and methods may be available. This has mainly to do with how the OLE server works. The Forms controls are actually Shapes that are drawn on the worksheet. These are also known as an Owner Drawn Controls, and function very differently from OLE controls. This is a lot to take in even for advanced users, so I hope I didn't confuse you.

    Sincerely,
    Leith Ross
    Leith thank you for replying

    I do understand that the form controls and activex controls are distinct from each other, I'm not really certain whether the forms controls from the IDE are identical to form controls accessable from the worksheet through the forms toolbar. But in general I have been able to understand the differences between activex and forms controls. This issue though is bizzarre to me.

    Why would microsoft present these events for these activex controls knowing in advance that they are not available in excel ?

    This is what's frustrating about VBA .

    This same type of circumstance exists for some of the methods and properties that are displayed in intellisense when coding.

    It's highly aggravating to have a method or property show in intellisense only for it to generate an error stating that it is not a property or method of this object.

    It defies all reasoning to have these focus events present in the event drop down of a worksheet containing these controls when these events are unavailable in excel.
    Last edited by SuitedAces; 10-03-2007 at 01:03 AM.

  12. #12
    Forum Contributor
    Join Date
    06-27-2006
    Posts
    310
    Mike thank you for replying.

    My knowledge with class modules isn't very strong.

    I have gone through one sample code in the past demonstrating With Events.

    And I may decide go through the these steps out of curiousity to see if these events do become available in a class.

    But either way it still leaves the question of why these events are being displayed in the events list of a worksheet for the controls.

    Again they don't do anything , and if they are available in a class , they probably won't fire there either.
    Last edited by shg; 10-25-2008 at 03:51 PM. Reason: deleted spurious quote

  13. #13
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello SuitedAces,

    It is frustrating, and there are reasons. Enough to fill a small book. This happens with all languages though. The very nature of programming is dynamic, not static. New methods are discovered and added while older techniques may be abandoned in their favor. Sometimes they remain for the sake of compatibility. If we could see the future of our decisions, we would have a perfect world, but we can't, and we don't. We just have to remain flexible, and be creative in finding solutions.

    Sincerely,
    Leith Ross

  14. #14
    Forum Contributor
    Join Date
    06-27-2006
    Posts
    310
    I've looked on msdn trying to track down some documentation and I'm unable to locate anything in reference to this question.

    I can't make any rational sense out of that.

    We're taking about software that a company invests tons of money in yet the documentation seems haphassard.

    Who short of people like Leith know why these events might not be functional in excel?

    Typical users sees these events available and naturally assume that they are functional in excel.

    Documentation on activex controls in the object browser or online as they apply to excel has been elusive.

    I haven't found it.


    Now that I have vented my spleen , I should just let it go and accept the fact that this type of slop is part of vba.
    Last edited by SuitedAces; 10-03-2007 at 01:28 AM.

  15. #15
    Forum Contributor
    Join Date
    06-27-2006
    Posts
    310
    Well Leith I just don't see why they didn't suppress those events from being listed in the events drop down.

    Or how about something in the help file as simple as ... this event is not functional in excel.

    Seems like that would have been simple enough being that they added properties to activex contols specify to excel.
    Last edited by shg; 10-25-2008 at 03:52 PM.

  16. #16
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Are you getting an events drop down for controls from the Forms menu.

    The word "Forms" in forms menu is a misnomer. The "forms" in mlForms.CommandButton does not refer the forms menu, it refers to userforms (I think)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1