Taking Screenshots In Your Access Database

Camera

In one of my applications, I wanted to enable my users to easily be able to take a screenshot of an Access database object of their choosing.

Now, there are some truly great tools out there, such as:

That said, my need was for an integrated tool with no installation! So what was one to do exactly?

The Basic Solution

Luckily for me, I had a great starting point. The reality was that I had help a user in a forum with this issue a while back. So I pulled a copy of the demo I had put together for them to review what I had actually done. The sample enabled the user to capture a screenshot of any form or report.

It was a relatively straightforward thing to achieve because both the Form and Report objects have a Hwnd property that we can easily get and then use to produce a screenshot from.

A More Versatile Solution

Now, although my original demo was good and would suit most people’s needs (think error reporting, grabbing images to include in presentations/emails, …), it didn’t meet all my needs in that it couldn’t capture tables, queries, …

I played around in the VBA editor, checked documentation, … and was disappointed, yet again, how Microsoft can’t standardize something as simple as creating an Hwnd property for all database objects!

So I pondered the issue, played around with code and finally saw no other option than to get into playing around with enumerating through the various Access application windows to find the ones I was after. With my trusty utility WinSpy++ I started running some tests and was able to find some standards, finally! something I could work with.

What I discovered was that Access appeared to use a set of standardized classes for the various Windows.

Object Type Window Class
Table OTable
Query OQry
Form OForm
Split Form OSplitView
Report OReport
Macro OScript

Now why Microsoft chose to abbreviate only the query class and not the Report, or any other will be a question we’ll never know the answer to 🤷🏻‍♂️, but at least I now had something I could work with!!!

I’m not going to post the code here, there is too much of it, and there is a downloadable sample below that you can dissect as you see fit, but the basic idea is quite simple, I simply iterate through all the Access Application windows looking for one that has the class of the object I am looking for as well as the name/title that I am searching for. Once I find that window, I get its Hwnd, ensure it is brought to the top (so it isn’t cutoff by other objects) and then I can use my original code to take a screenshot.

The UI, You Say

While I was developing this ‘utility’ and was dissecting the design of the Access application, the windows layout … I decided it might be useful at times to be able to take a screenshot of something like the:

  • Ribbon
  • Navigation Pane
  • MDI Client (the actual work area where everything (tables, queries, forms, reports, …) are displayed
  • Status Bar

So I’ve also included that ability within the demo as I thought it might be useful to some.

Hard to Use You Say!

Although I didn’t want to post all the necessary code, APIs, … I thought I’d at least demonstrate the actual code used to make the screenshot so you can see just how simple it is to actually use.

Object Example Call
Table Call TakeScreenshot(“YourTableName”, “OTable”)
Query Call TakeScreenshot(“YourQueryName”, “OQry”)
Form Call TakeScreenshot(“YourFormName”, “OForm”)
Form Call TakeScreenshot(“YourSplitFormName”, “OSplitView”)
Report Call TakeScreenshot(“YourReportName”, “OReport”)
Macro Call TakeScreenshot(“YourMacroName”, “OScript”)
Ribbon Call TakeScreenshot(“MsoDockTop”, “MsoCommandBarDock”)
Navigation Pane Call TakeScreenshot(“Navigation Pane Host”, “NetUINativeHWNDHost”)
MDI Client Call TakeScreenshot(“”, “MDIClient”)
Status Bar Call TakeScreenshot(“MsoDockBottom”, “MsoCommandBarDock”)
Access Application Call TakeScreenshot(“Access Application”, “Application”)

So as you can see, it is very simple, a single line, and you can take a screenshot of pretty much any database objects or UI element you want.

The Demo

In my demo, I setup a form with a combo box that allows you to simply specify which object to take a screenshot of and then you need only click on the Take Screenshot button. Obviously, you could integrate this into a custom ribbon or onto individual objects.

This implementation as a whole has the added benefit of not requiring any extra software to be installed on the user’s PC. Also, the user doesn’t need to finagle the edges of objects … trying to select the proper area to capture, they only need to click a button. That’s it!

My code also offers the ability to control whether or not the created image is opened after the capture.

One more great thing with this code is that it even works when the object is in Design View! So now it is possible to easily capture objects in any view mode.

It should also be noted, that although I did develop this specifically for my Access needs, it can very easily be adapted for use in almost any other VBA environment (Excel, Word, …). It is just a question of using WinSpy++ to figure out the class if direct access to Hwnd is not already available through some VBA property.

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 demo copy by using the link provided below:

Download “Access Screenshot Demo (x32 accdb)” Screenshot.zip – Downloaded 7388 times – 96.40 KB

Version History

 

Version Date Changes
V1.000 Initial Release
V1.001 2020-06-20 Takes screenshots of Forms and Reports and was created to help a forum user.
V1.002 2021-11-17 Improved version that can take screenshots of Tables, Queries, Forms, Reports, Macros and various UI elements.
V1.003 2022-07-11 Added necessary code to deal with Split Forms

A Few Resources on the Subject

8 responses on “Taking Screenshots In Your Access Database

  1. Ayman

    Great tool, however it is not working with me i get the error message the code in this project must be updated for use on 64-bit system. please review and update declare statements and then mrk them with the ptrsafe attribute

    is there a 64 bit version of the code

      1. ayman

        would it be possible to buy such service from you , I’m not expert in programming and barely have the basics.

      2. ayman

        or if it is possible to buy customized copy to only screen capture a form and export it as JPG to specified folder

        1. Daniel Pineault Post author

          You can do anything you want with VBA. So yes, it can be done.

          The TakeScreenshot procedure calls the GetScreenshot function and in that call the filename to be used is specified. So you can easily override the path and/or filename there.

          1. ayman

            🙂 i know it can be done by expert such as yourself.
            I’m trying to get in touch with you through the contact us form without luck. is it possible to respond to the emails .

          2. Daniel Pineault Post author

            I did reply to one e-mail and posts here as well. I have no plans in the near future to adapt my code for 64-bit. If you, or someone else, wishes to do so you are more than welcome to, but I’m currently not available.

  2. Nicolas

    Works like a charm !
    Excellent tool; many thanks for providing it.
    However, I had to change the value of ‘sClass’ from “OForm” to “OFormNoClose” in order for it to work with my forms.

    FWIW, the parameters I use for my forms are listed below.

    Border Style = none
    Record Selectors = no
    Navigation Buttons = no
    Scroll Bars = neither
    Control Box = no
    Close Button = no