Results 1 to 6 of 6
  1. #1
    Epidural is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    15

    ActiveControl form Events - VBA

    I need to perform certain scripts when Me.ActiveControl changes; how might I go about this? I havn't been able to find a suitable event. This needs to be done for all controls, so writing "On Got Focus" for each event is far too tedius.



    Code:
    Private Sub SOME_ON_CHANGE_EVENT()
        Dim desc As String
        desc = "Description:" & vbCrLf & cbCrLf & Me.ActiveControl.Name & vbCrLf & vbCrLf & Forms(Me.Form.Name).Controls(Me.ActiveControl.Name).StatusBarText
        Me.txtInfo.Caption = desc
    End Sub
    As you can see, I'm trying to put the description of the field into a viewable "Description" box standardized across my forms. When the user clicks the control (or better yet, hovers over the control) the above code should be executed. Ideas involving little work (ie not having to do it for each control) ?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Don't know of any event that would accomplish this.

    The procedure could be a function that could be called by each control's GotFocus event. The function call can be directly in the event property line.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    To do this by hovering over Controls is going to require code in an event for each Control, even if it's just Calling a function common to all of the Controls, such as one displaying the Control Name. But to trigger your code each time a character is entered into any Textbox/Combobox, for instance, in Form Design View, with the Form itself selected, go to Properties - Events and set the Key Preview Property to Yes. Then use your code in the Form_KeyDown event:
    Code:
    Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
      Dim desc As String
      desc = "Description:" & vbCrLf & cbCrLf & Me.ActiveControl.Name & vbCrLf & vbCrLf & Forms(Me.Form.Name).Controls(Me.ActiveControl.Name).StatusBarText
      Me.txtInfo.Caption = desc
    End Sub
    Linq ;0)>
    Last edited by Missinglinq; 05-19-2012 at 07:47 PM.
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Just remembered controls have a ControlTipText property. This property gives controls a 'popup tip on hover' behavior.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Epidural is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    15
    Quote Originally Posted by June7 View Post
    Don't know of any event that would accomplish this.

    The procedure could be a function that could be called by each control's GotFocus event. The function call can be directly in the event property line.
    I think this might be enough; I don't have to enter it for all fields individually as I just learned you can multi-select things and simply write the event once to have it appear across all fields (kind of like how re-tagging a bunch of songs with one artist by selecting the songs and changing one's artist changes them all).

    However, what is the syntax for calling the procedure from the OnClick: [Event Procedure] property line?

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Just enter the name of the function preceded by = sign and followed by parens: =MyFunctionName()
    Last edited by June7; 05-22-2012 at 03:08 PM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. events on RECORDS?
    By vt800c in forum Access
    Replies: 1
    Last Post: 05-27-2011, 09:15 AM
  2. Help with gotocontrol, activecontrol
    By k9drh in forum Forms
    Replies: 5
    Last Post: 04-21-2011, 10:12 AM
  3. Different Events
    By jo15765 in forum Programming
    Replies: 2
    Last Post: 12-07-2010, 12:45 PM
  4. Replies: 0
    Last Post: 12-28-2009, 12:14 PM
  5. form events
    By EinSpringfielder in forum Programming
    Replies: 1
    Last Post: 08-26-2009, 11:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums