Access – Auto-Closing Forms

In a forum, the question was

Is there a way to automatically close a form once the cursor was moved off of it.

I don’t know why, but this was one of those forum questions that truly got me curious and so I needed to find a way to do this for my own personal knowledge.

I came up with an initial solution, but it wasn’t foolproof and wouldn’t necessarily work for all setups and so I slept on it and woke up with a fundamentally simple solution. I have to admit, the solution only came to me because of some recent work I had to do for a client which required me to override the system cursor (in an Outlook project) and so I had become aware of certain available cursor APIs. Armed with this basic knowledge, I figure there had to be a way to compare the cursor’s position against the form’s boundaries and so the solution was born! With 2 simple APIs and the form’s timer event, it became pretty straightforward to accomplish and can be ported to pretty much any setup.

The following demo has everything you need (both 32 and 64-bit API declarations) with a working example so you can dissect the concept to be in a position to integrate it into your own project.

Disclaimer/Notes:

If you do not have Microsoft Access, simply download and install the freely available runtime version (this permits running MS Access databases, but not modifying their design):

Microsoft Access 2010 Runtime
Microsoft Access 2013 Runtime
Microsoft Access 2016 Runtime
Microsoft 365 Access Runtime

All code samples, download samples, links, ... on this site are provided 'AS IS'.

In no event will Devhut.net or CARDA Consultants Inc. be liable to the client/end-user or any third party for any damages, including any lost profits, lost savings or other incidental, consequential or special damages arising out of the operation of or inability to operate the software which CARDA Consultants Inc. has provided, even if CARDA Consultants Inc. has been advised of the possibility of such damages.

Download a Demo Database

Feel free to download a 100% unlocked demo copy by using the link provided below:

Download “Access - Auto-Closing Forms” AutoClosePopup_V1.000.zip – Downloaded 5298 times – 37.16 KB

Version History

Version Date Changes
V1.000 2020-02-28 Initial Release