[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 534
  • Last Modified:

Automatically take a screenshot and save to disk?

Hi, I'm using Access 97.

I've searched around for over an hour, and I haven't found any working code in Access to take a screenshot of the current screen and save it to disk.  I found lots of VB 6 examples, but they won't run in VBA (I get hung up on the SavePicture function).

Does anyone know of a good way to capture a screenshot of the current screen, and save it to disk somewhere?

Thanks!
0
raterus
Asked:
raterus
  • 11
  • 7
  • 2
3 Solutions
 
ImoutwestCommented:
Searched EE and found the following:

The following site (the one from the question is no longer available) provides a possible solution, however, although it once was free, it would seem that the cost is now $15.

http://www.hypersnap-dx.com/ or http://www.hypersnap-dx.com/

One of the bullets: - Automatically saves your captures to graphics files.

Hope this helps, imoutwest
0
 
ImoutwestCommented:
BTW, not for the points, just trying to help. (Would be helpful to do somethings similiar)
0
 
raterusAuthor Commented:
I ran across this post too while search, but I don't want to use a third-party component here, the access database is used on an intranet, and running around to everyone's computer to install the component  is not an option.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
If it's not here

http://www.lebans.com/products.htm

or

http://www.mvps.org/access/

then ... it hasn't or cannot be done:

mx
0
 
ImoutwestCommented:
Understand, a possible work around could be to use the sendkeys (sometimes necessary) and copy your screen shot to the clipboard (probably already figured that out), the copy that data in an unbound ole control (hidden) on your form, then use the following from the master...

http://www.lebans.com/oletodisk.htm

Haven't tried it yet, but should be a push in the generally right direction.
0
 
ImoutwestCommented:
mx, do you have a link for everything (in a indexed database maybe)?
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Sort of :-)

but  puppydogbuddy is the link Master .

mx
0
 
raterusAuthor Commented:
The oletodisk database Imoutwest posted has given me hope this can be done.  But going back to the code I was originally trying to get to work, I still can't get the screen shot into an Image control.  The problem is the screenshot examples I find for VB 6 use the API with GetDC/BitBlt/etc. and have calls to the ".hDC" property of the Image control, or the form, but I don't think this .hDC property is supported in Access.

I'm looking now for a way to perhaps copy the screenshot to the clipboard and copy it to the Image control.  Or a way to use a .hDC property in an access form.  Any help with that is certainly appreciated!
0
 
ImoutwestCommented:
I can't test an example until tomorrow,

Make a new form and add an unbound ole control.
Copy your screen to the clipboard.
Then right click on the control and paste from the clipboard or hit Ctrl - V.

If that works then perhaps that is another push, I'll try this tomorrow. Imoutwest
0
 
raterusAuthor Commented:
Keyword here is "Automatically", so any user interaction is out!  What I'm trying to do is grab a screenshot of the desktop when an error occurs, because users never report errors!
0
 
ImoutwestCommented:
I understand,

Once you verify that the copy and paste will work, then you can place the sequence in VBA and make it part of which ever event meets your requirement.
0
 
raterusAuthor Commented:
Problem, and maybe my limited frame of mind of Access 97 is affecting this.  I can hit print-screen, and paste the image into an OLEUnbound control.  However this only works at design time.  I have to get this to work at runtime right?

I'm thinking I need a new strategy.  My users are all on an intranet, and the .Net framework is on all of their computers.  I might just start up another program that takes the screenshot and avoids all this fuss!
0
 
ImoutwestCommented:
So...

You're wanting to capture the screenshot when an error occurs and then send that back to you?

Unless you need to see the screen (which you probably want to) you can create a global error handler that sends you an email when an error occurs (or for when unhandled errors occur).
0
 
raterusAuthor Commented:
Global error handler?  How does one set that up?  I didn't even know this was possible!
0
 
ImoutwestCommented:
There are several examples out there...
I will gladly send you one tomorrow (sorry I can't get the file today).

Basically it is a variation of the Access error handler (like when you use the wizard to add a command button), but you create a module (function) that is call each time there is an error. I'll paste it here tomorrow morning.

Imoutwest
0
 
ImoutwestCommented:
' Example of Error Handler
On Error GoTo Err_cmdClear_Click

    ' Your code goes here
   
Exit_cmdClear_Click:
    Exit Sub

Err_cmdClear_Click:
    Call GblErrHandle(Err.Description, Err.Number, Me.name, Me.ActiveControl.name, Erl)
    Resume Exit_cmdClear_Click

' Paste the following in a module - I use a select case to handle the listed errors, all unhandled error send me an email. Outlook will ask the User for permission to send an email, so the User will know that an 'Error' occured and that an email is being sent to the administrator.

'   Found a Error Handler created by Rob Henderson, Developers For Hire Ltd. -- developersforhire.co.uk --
'   Used his basic code to create my own that allows for trapping all errors and then through a Select Case
'   Ignores listed errors and traps and records unlisted.

Function GblErrHandle(ErrorDescription As String, ErrorNumber As Long, WhichForm As String, WhichControl As String, WhichLine As Integer) As Boolean
On Error GoTo Err_GblErrHandle
   
    Dim strMsg As String
   
    GblErrHandle = True
       
    Select Case ErrorNumber
        'Case 13: Exit Function ' Type mismatch
        Case 94: ' Null
            strMsg = "You have either Left a Required Field Blank  " & vbCrLf & vbCrLf & _
                    Space$(25) & "Or" & vbCrLf & vbCrLf & _
                    "A Required Field has an Invalid Entry" & vbCrLf & vbCrLf & _
                    "If Printing Labels: Ensure they have been Verified" & vbCrLf & vbCrLf & _
                    "Please Fill In the Required Information and Select Again"
                ' Display Error Message to User
            MsgBox strMsg, , "Left a Required Field Blank"
            Call CreateErrorLog(ErrorDescription, ErrorNumber, WhichForm, WhichControl, WhichLine)
            Exit Function
        Case 1004: 'trap error 1004 - path/filename specified cannot be found
            strMsg = "The input path/file could not be found.  " & vbCrLf & _
                    "Make sure the path and file name are spelled" & vbCrLf & _
                    "correctly on form Application Parameters " & vbCrLf & _
                    "and/or that the source file actually" & vbCrLf & _
                    "exists at the location specified.  Contact " & vbCrLf & _
                    "the application administrator if you need help."
                ' Display Error Message to User
            MsgBox strMsg, , "Input File Error"
            Exit Function
        Case 2001: Exit Function ' Canceled the previous operation.
        Case 2046: ' The command or action 'Paste' isn't available now.
            strMsg = "Can't Paste if the Record is Locked!"
            MsgBox strMsg, , "Command or Action Not Available"
            Exit Function
        Case 2103: ' The report you entered is misspelled or refers to a report that doesn't exist.
            Call CreateErrorLog(ErrorDescription, ErrorNumber, WhichForm, WhichControl, WhichLine)
            Exit Function
        Case 2164: ' You can't disable a control while it has the focus.
            Call CreateErrorLog(ErrorDescription, ErrorNumber, WhichForm, WhichControl, WhichLine)
            Exit Function
        Case 2427: ' Entered an expression that has no value.
            Call CreateErrorLog(ErrorDescription, ErrorNumber, WhichForm, WhichControl, WhichLine)
            Exit Function
        Case 2501: ' Cancel
            'Call CreateErrorLog(ErrorDescription, ErrorNumber, WhichForm, WhichControl, WhichLine)
            Exit Function
        Case 3197: ' The Search Key was not found in any record
            MsgBox "Write Conflict"
            Exit Function
        Case 7874: ' Can't find the object
            Call CreateErrorLog(ErrorDescription, ErrorNumber, WhichForm, WhichControl, WhichLine)
            Exit Function
        Case -2147352567: 'You can't assign a value to this object.
            Call CreateErrorLog(ErrorDescription, ErrorNumber, WhichForm, WhichControl, WhichLine)
            Exit Function
        Case Else:
                ' Call the LogErrorToTable function to record the error in a table
            Call CreateErrorLog(ErrorDescription, ErrorNumber, WhichForm, WhichControl, WhichLine)
                ' Format Error Message
            strMsg = strMsg & "There has been an error in the application." & vbCrLf & vbCrLf & _
                "Error Number: " & Space$(6) & ErrorNumber & vbCrLf & _
                "Error Description:  " & ErrorDescription & vbCrLf & _
                "Error Location: " & Space$(5) & WhichForm & vbCrLf & vbCrLf & _
                "Please note the above information has been written " & vbCrLf & _
                "to the application Error Log Table." & vbCrLf & vbCrLf & _
                "Please contact Timothy Dixon, tdixon@nwkinetics.com" & Space$(8)
                ' Display Error Message to User
            MsgBox strMsg, vbInformation, "Error Log."
    End Select

Exit_GblErrHandle:
    Exit Function

Err_GblErrHandle:
    GblErrHandle = False
    strMsg = "The Error Handler has failed.  Contact " & Space$(5) & vbCrLf _
            & "Timothy Dixon immediately."
    MsgBox strMsg, vbCritical, "Error"
        ' Send eMail
    DoCmd.SendObject acSendNoObject, , acFormatXLS, "Admin Email Address", , , "Name of your database", _
        Err.Description & "   Error Number   " & Err.Number & "    User   " & _
        Application.CurrentUser & " Officer Code " & Environ("UserName"), False
    Resume Exit_GblErrHandle

End Function

'Good Luck, hope this helps. Imoutwest
0
 
ImoutwestCommented:
' Call the LogErrorToTable function to record the error in a table
I didn't include this function, it records the error into a table
0
 
raterusAuthor Commented:
*Sigh* I think your concept of "Global error handler" and mine are completely different.  In my world (.Net), you can set up a real global error handler, and not even have to worry about rigging up every sub/function to call it, in case something goes wrong.

Sadly, I didn't think this was possible in Access, and based on what I see here, it's still not possible.  I do thank you for all your help you've been on this question to me, even if you've only steered me away from things!  Now I just need to sit down and put it all together.
0
 
ImoutwestCommented:
Sorry if I lead you down the wrong path... Never my intention. Best of luck with your project. Imoutwest
0
 
raterusAuthor Commented:
I ran around in circles a few days with this.  I eventually concluded you'd have to use a 3rd party component.  
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 11
  • 7
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now