Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049

    Unanswered: On Error Take Screenshot!

    Hey, does anyone know if it's relatively easy to take a screenshot if an error occurs?

    Has anyone ever done this?

    It would save me some serious time in debugging those mysterious errors that often turn out to be user errors despite their totally denying it could be.

    TIA
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Dunno, but you will also then have to access the clipboard (I think I had code for this....) and drop the image somewhere. You got a plan for all that lot before investigations commencify?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Sep 2002
    Location
    South Wales
    Posts
    580
    Hi StarTrekker,

    Hope Australia is treating you well.

    I haven't tried this myself, but here is a link by Lutz Gentkow MVP for 2 methods using SendKeys (WordBasic so prob not relevant) and more importantly API Calls:

    How to do a screen capture using VBA

    I just did a quick test and turned the API code into a public function which seems to work (I Created a test form and had a button event which divided 1/0, behind the button I had on err goto errTrap: and called the Function from their:

    Option Compare Database
    Option Explicit

    Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal _
    bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    Private Const VK_SNAPSHOT = &H2C

    Public Function CaptureScreen()

    keybd_event VK_SNAPSHOT, 1, 0, 0

    End Function

    This copies a screenshot into the clipboard which is what I think? You are trying to do.

    Hope this is of help.
    Windows Server 2003-8 / Terminal Services / SQL 2000 / Access 2003 / Office 2003-7 / Exchange 2003-7 / Blackberry Enterprise Server / AutoCAD / Lambert And Butler / Red Bull

  4. #4
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Thanks garethdart, that seems to be step 1 taken care of

    Quote Originally Posted by pootle flump
    Dunno, but you will also then have to access the clipboard (I think I had code for this....) and drop the image somewhere. You got a plan for all that lot before investigations commencify?
    Not yet, one step at a time. But the end result should be so very handy

    Guess what my next topic is going to be
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  5. #5
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Is there a need for another topic? All seems related

    Ok so after gareth's post, I now have the screen being stored in the clipboard, so now I need to write a file from the clipboard contents.

    Anyone done this before? Any clues as to what I need to do next?

    TIA
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  6. #6
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by StarTrekker
    Anyone done this before? Any clues as to what I need to do next?

    TIA
    I have code at home, but it is more API stuff so not written by me. Although looking at the below it reminds me that I was retrieving text. Dunno about bitmaps....
    Manipulating the clipboard using VBA
    Testimonial:
    pootle flump
    ur codings are working excelent.

  7. #7
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    try google for "stephen lebans windowtobitmap"
    -yes, his example code attacks the relationship window, but i guess everything you need is there.

    izy
    currently using SS 2008R2

  8. #8
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Thanks guys, will check it out and report back
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  9. #9
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    hi 'Trekker,

    i spent a pleasant hour trying adaptations of Stephen Lebans' approach before asking myself why?
    the form grafix are of no interest, the content is what counts.

    why not consider something radically simpler to implement:
    Code:
    Private Sub gotError()
        Dim ctl As Control
        Dim strBuff As String
        On Error Resume Next
        Debug.Print "Error " & Err.num & " occurred in " & Me.Name; " & with the following status:"
        Debug.Print "Form is Dirty: " & Me.Dirty
        Debug.Print "Active control: " & Me.ActiveControl.Name
        'etc - there is a bucket load of properties you might want to dump to log
        On Error GoTo err_gotError
        For Each ctl In Me.Controls
            strBuff = ctl.Value
            Debug.Print ctl.Name & ": " & strBuff
        Next
    exit_gotError:
        Exit Sub
    err_gotError:
        Select Case Err.Number
            Case 94
                strBuff = "NULL"
            Case 438
                strBuff = "'Value' property is not supported by this control"
            Case Else
                strBuff = "Unanticipated error " & Err.Number & "-" & Err.Description
        End Select
        Resume Next
    End Sub
    replace debug.print with your favourite "write a log line" routine and it is done (done smaller, done faster, done simpler).

    izy
    Last edited by izyrider; 03-21-09 at 15:00.
    currently using SS 2008R2

  10. #10
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    It definitely is simpler to code that Izy. I already have a "write to log" thing going on, but there are some errors that I am finding it incredibly difficult to isolate a cause. I figured that if I could see the screen at the time it might help, hence the thought for screenshotting when an error occurs.

    It's starting to get shuffled to the "too hard" basket though, so your suggestion is a good one, thanks
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  11. #11
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    try the attached if an approximation will do.

    it has an unfortunate "pixel wrap" effect: extreme right pixels wrap round to the left of the BMP but other than that it works ok.
    getting it right will take too long for a freebie

    izy

    LATER:
    pixel-wrap fixed in rev 06 (see a couple of posts down)
    rev 04 removed from this post.
    Last edited by izyrider; 03-23-09 at 15:27.
    currently using SS 2008R2

  12. #12
    Join Date
    Sep 2002
    Location
    South Wales
    Posts
    580

    Thumbs up Izy Suggestion

    Good thinking Izy and handy bit of code.

    Windows Server 2003-8 / Terminal Services / SQL 2000 / Access 2003 / Office 2003-7 / Exchange 2003-7 / Blackberry Enterprise Server / AutoCAD / Lambert And Butler / Red Bull

  13. #13
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    couldn't resist it - updated to rev 06 fixing:
    - palette construction error
    - pixel data offset error
    - a lot of orphaned code removed
    ...so now the pixel-wrap issue seems to be resolved

    one problem remains: the .BMP has some whitespace off to the right of the form - not pretty, but not a big deal for 'Trekker's crash-tracker scenario. the error seems to be somewhere in the mScreenWidth calculation/manipulation but i don't find it - if someone finds a fix, please post here (or at least drop me a PM).

    izy
    Attached Files Attached Files
    currently using SS 2008R2

  14. #14
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    That's great IZY, it might just do as it is.... I'll let you know how it goes once I get it up and running.

    Awesome stuff! Thanks
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  15. #15
    Join Date
    Jul 2009
    Posts
    1

    Nircmd

    I use Nircmd.exe as a function call
    Free Command line utility.

    NirCmd - Windows command line tool

    Here is the code:

    Dim NirFileLoc As String
    Dim SavLoc As String
    NirFileLoc = CurrentProject.Path & "\ProgramData\Batch-exe\nircmd.exe"
    SavLoc = " savescreenshot C:\" & Format(Now(), "hhnnss") & ".png"
    Shell Chr$(34) & NirFileLoc & Chr$(34) & SavLoc & Chr$(34)
    End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •