> ## Content Index
> Fetch the complete content index at: https://nolongerset.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# AccHitTest: Returns the Form Control the Mouse Clicked On
- URL: https://nolongerset.com/acchittest/
- Published: 2022-08-02T03:05:02.000Z
- Updated: 2026-05-08T12:55:55.000Z
- Description: This undocumented form function can help you write a generic click event for label controls.
- Author: Mike Wolfe
- Tags: Hidden Features, #FormFunctions, Code Library, #Import 2026-05-20 02:59

The other day on LinkedIn, [Shashvat Gupta posed](https://www.linkedin.com/feed/update/urn:li:activity:6958122692734541824?utm%5Fsource=linkedin%5Fshare&utm%5Fmedium=member%5Fdesktop%5Fweb) a deceptively difficult challenge:

> Suppose there are 10 labels on a form and I want to write a common function that shows the label name on which double click event is triggered.  
>  
> Now, in double click event for each label, I have call to the common function, to which I have to pass label name.  
>  
> Is it possible to have a line of code in the double click event of each label that can dynamically give me the label name (instead of passing a hard-coded value) ?

## Label Controls: A Unique Challenge

The deceptively challenging part is that Labels cannot receive focus. 

Why does that matter? It means that you can't use one of my favorite tricks for adding generic event handlers to form controls: the `ActiveControl` function. For example, in my recent article on [adding modern on/off switches](https://nolongerset.com/modern-on-off/) in Access, I set the following expression in the AfterUpdate event of the toggle button:

```vba
=FormatToggle([ActiveControl])
```

This approach lets you select multiple controls and set their event handler properties at one time.

Unfortunately, since Labels cannot receive focus, they can *never* be the ActiveControl.

## AccHitTest: An Elegant Solution

In the comments, Access MVP Karl Donaubauer [offered a solution](https://www.linkedin.com/feed/update/urn:li:groupPost:1641627-6957209808059924480?commentUrn=urn%3Ali%3Acomment%3A%28groupPost%3A1641627-6957209808059924480%2C6957757977139249152%29) I had never even heard of: the undocumented form function `AccHitTest`.

> That's a typical use case for the undocumented form function AccHitTest, which could look like this in the class module of the form:
> 
> ```
> Private Type POINTAPI
>   x As Long
>   y As Long
> End Type
> 
> Private Declare PtrSafe Function GetCursorPos Lib "user32.dll" _
>    (ByRef lpPoint As POINTAPI) As Long
> 
> 
> Private Function fctClickLabel()
> 
>   Dim pt As POINTAPI
>   Dim accObject As Object
>   
>   GetCursorPos pt
>   Set accObject = Me.AccHitTest(pt.x, pt.y)
>   
>   If Not accObject Is Nothing Then
>       Debug.Print accObject.Name
>   End If
> 
> End Function
> 
> ```
> 
> In the (double) click property line of the labels you write: `=fctClickLabel()`

The `AccHitTest` function is a method of the form object. That's why it's called as `Me.AccHitTest` in Karl's sample code above. That also means that the sample code must be called from the form's code-behind module.

## Creating a Generic Function

The sample approach works well for one form, but what if you wanted to create a generic function that you could call from multiple forms.

The code is almost identical, except that you will need to pass an instance of the form object to the function:

```vba
'Copy and paste the following code into a Standard module
Private Type POINTAPI
   x As Long
   y As Long
End Type

Private Declare PtrSafe Function GetCursorPos Lib "user32.dll" _
    (ByRef lpPoint As POINTAPI) As Long

Function ShowControlName(Frm As Form)

   Dim pt As POINTAPI
   Dim accObject As Object
   
   GetCursorPos pt
   Set accObject = Frm.AccHitTest(pt.x, pt.y)
   
   If Not accObject Is Nothing Then
       MsgBox "You just clicked on " & accObject.Name
   End If

End Function
```

Here's how you would call the above function from a control's event handler:

- **On Click:** `=ShowControlName([Form])`

## Background Information

I asked Karl how he learned about this hidden feature and he replied to me via email. Here was his response (*shared with permission*):

> I learned about AccHitTest in discussions in the German NNTP newsgroups. The function is certainly older, but I saw it [first mentioned there in 2004](ttps://groups.google.com/g/microsoft.public.de.access/c/OwPDa3joCr0/m/3yP3Bt3rPHAJ) by the Viennese (of course ;-) Gottfried Lesigang.   
>  
> Later it was "popularized" as a solution in our discussions (e.g. [here](https://groups.google.com/g/microsoft.public.de.access/c/TFUgcOGEJKQ/m/uaZ5H5MjHt4J) combined with a timer) by the German colleague Jörg Ostendorp, who then also mentioned it [in the script](https://www.donkarl.com/Downloads/AEK/AEK10%5FAPI.zip) and an example db of an API talk for my German-language conference AEK in 2007\. Lucky you, who learned some German. ;-) \[NOTE: Karl is referring to the one year of German I took in college, of which I remember roughly nichts <-- I even had to Google "[nichts](https://translate.google.com/?sl=auto&tl=de&text=nothing&op=translate)"🤦‍♂️\]  
>  
> If you activate the hidden members in the VBA object browser and search for it, you can see that it exists for many types of controls.

Here's what Karl meant about activating hidden members in the Object Browser and searching for "AccHitTest":

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2022/08/image.png)

## Origins of the AccHitTest Function

The "Acc" in AccHitTest stands for "Accessibility" and NOT "\[Microsoft \]Access."

The versions of this function in the Access object model are almost certainly a wrapper around the [IAccessible:accHitTest method](https://docs.microsoft.com/en-us/windows/win32/api/oleacc/nf-oleacc-iaccessible-acchittest) from the Windows API:

> The **IAccessible::accHitTest** method retrieves the child element or child object that is displayed at a specific point on the screen.

Now, if you'll excuse me, I take my leave in search of nails to pound with my newfound hammer...

*Image by [Steve Buissinne](https://pixabay.com/users/stevepb-282134/?utm%5Fsource=link-attribution&utm%5Fmedium=referral&utm%5Fcampaign=image&utm%5Fcontent=682767) from [Pixabay](https://pixabay.com//?utm%5Fsource=link-attribution&utm%5Fmedium=referral&utm%5Fcampaign=image&utm%5Fcontent=682767)*