When accHitTest generates an 'invalid procedure call or argument' error

CJ_London

Super Moderator
Staff member
Local time
Today, 03:45
Joined
Feb 19, 2013
Messages
17,350
Using win11, Access 365 64bit

I have this simple bit of code:
Code:
Function setReconciled()
Dim PT As POINTAPI

    GetCursorPos PT
    Set YNctl = Me.accHitTest(PT.X, PT.Y)
    
End Function

Which has worked fine for many years, but I've discovered the above error can be generated in certain circumstances.

my monitors are setup like this

1743077847636.png


The issue is not so much the acchittest call, but what it does with what getcursorpos returns. If the form is on my laptop monitor (1) and is my main display, everything works fine. But if on one of my other monitors cursorpos generates a negative Y value.

with 1 being the laptop monitor and main display - so PT(0,0) is top left of that monitor

If I change the main display to be monitor 3 (my usual setup) and have the form on that monitor then the code runs fine. Move the form to one of the other monitors and it again fails.

On the other hand if I make monitor 2 my main display, then the code works on any monitor.

My conclusion is that acchittest will only accept positive X and Y values - if the form is on the far left of monitor 1 then the error returns if the cursor is in that location when the code is triggered (a negative X value).

My solution for now is to make monitor 2 my main display but would be interested to know if others have had this problem and if there is a workaround by adjusting PT
 
My conclusion is that acchittest will only accept positive X and Y values - if the form is on the far left of monitor 1 then the error returns if the cursor is in that location when the code is triggered (a negative X value).

Correct. I reported this issue to the Access team and discussed this issue in several of my articles based on the use of accHitTest in early 2024.

1743081689203.png


For example, see



The Access team acknowledged this is an issue but it has not yet been fixed. This is a significant issue for those who need to rely on accHitTest for accessibility reasons.

Interestingly, the similar accLocation function doesn't have the same problem. However, accHitTest is more precise.

For now, if you need to rely on accHitTest, the only solution is to make your left hand monitor the primary display so that all co-ordinates are positive. You should do that even if you use another monitor as your main monitor
 
Thanks for the clarification - so not a win11/365 or 64bit issue as I didn't experience it with win10/2010/32bit - but then I didn't have a laptop in my monitor mix

I've looked at accLocation in the past, but for that to work I would need to use a timer to track the cursorpos and loop through all controls to see which one the cursor happens to be over at the time.

There are no doubt other ways - using a class or multiple mousemove events for example - but for now assigning the main monitor to top left will suffice - keeps to code simpler :)
 
I haven't used accLocation in a couple of years or so but I can't think why you think you would need a timer.
 

Users who are viewing this thread

Back
Top Bottom