Home Case Studies MS Office Tips and Tricks Sample Code Helpful Videos Custom Development  Custom Training Join Us Contact Us
Search Our Site:  

Snag It VBA Code

I Get It! Development uses SnagIt® screen capture software to produce classroom materials, technical documentation and the company newsletter. Its sister product, Camtasia Studio®, is used to produce the Tips and Tricks videos on the website. If you're not familiar with either of these products, you can download a free evaluation at www.techsmith.com.
TechSmith products support VBA. It allows any VB or VBA user to programmatically capture images--still or moving--from the computer screen. I Get It! Development was interviewed for its use of SnagIt VBA.

SnagIt's support of VBA is a huge boon to database developers using Access as a front end. Access VBA does not print out forms as other flavors of VB and VBA do. This makes documentation of such an application a tedious process.

A Word From Our Sponsor

Great presents for babies
Great presents for babies


Access forms must be displayed in design view and/or form view and then, typically, captured via Print Screen. The resulting capture must then be pasted into a file and named appropriately or pasted directly into Word along with the form's code. With SnagIt VBA, a simple loop through the forms with a SnagIt capture for each form creates the screen captures and saves them to disk in moments. See below for the code.
Adobe Acrobat® also supports VBA. Once the screen captures are created, the forms can be looped through once again and each screen capture is placed before its code, or placed at the end of the documentation. See the Adobe VBA code page for the code.

If you'd like to download a sample database, try this Inventory Control Example.zip
'---------------------- Start module ------
'I Get It! Development provides programming examples
'for illustration only, without warranty either
'expressed or implied, including, but not limited to,
'the implied warranties of merchantability and/or
'fitness for a particular purpose. This article
'assumes that you are familiar with the programming
'language being demonstrated and the tools used to
'create and debug procedures. These examples assume that
'you have licensed copies of all relevant software installed
'on the machine upon which the examples will be run.

'I like to capture forms in design view to see
'bound/unbound fields. This produces some problems as
'we will see below in the FindHeight function.

'Remember to close all open forms (they'll get closed anyway)
'and minimize the database window just for good measure.
'We grab windows by their 'handle' and if two windows overlap,
'We can get part of one window and part of another - not
'a pretty picture (pun intended)

'All form captures go into a folder called C:\Documentation as [formname].jpg
'Please change this to an existing folder or create the folder
'on your system

'Remember to set the SnagIt Type Library Reference in the
'VB Editor under Tools>References!

'-------------Written by Theo Callahan 4/2003 theo@igetit.net --------------

'I set S Public just so I wouldn't be opening and closing
'Snagit dozens of times. The ActiveX server blows up.
Public S As SNAGITLib.ImageCapture
'This is described as a function since Access toolbars only
'call functions... there are no arguments or return values
Public Function CreateScreenShots()
Const HMARGIN_ERROR As Integer = 375 'Add a little height
Const VMARGIN_ERROR As Integer = 625 'Add a little width
Dim objCurrent As AccessObject
Dim frmCurrent As Form

'Instantiate a SnagIt app
Set S = CreateObject("SNAGIT.ImageCapture")

For Each objCurrent In CurrentProject.AllForms

    If objCurrent.IsLoaded Then
        'If it's loaded we have to close it.. sorry!
        'It may overlap another form and SnagIt will grab any
        'overlapping pieces
        Set frmCurrent = Forms(objCurrent.Name)
        DoCmd.Close acForm, objCurrent.Name, acSavePrompt 'maybe someone's working on it?
    End If

    
'open the form in design view
    DoCmd.OpenForm objCurrent.Name, acDesign, , , acFormPropertySettings, acWindowNormal
    Set frmCurrent = Application.Screen.ActiveForm

    'Make it the right size for printing BTW, make sure
    'there's a printer defined! Otherwise this blows up!
    'We don't know how HIGH the form is... run FindHeight function
    With frmCurrent
        .InsideWidth = .Printer.ItemSizeWidth + HMARGIN_ERROR
        .InsideHeight = FindHeight(frmCurrent) + VMARGIN_ERROR
    End With

    'Now capture the thing
    'We give the Windows handle for the form window to capture, the form name for the
    'jpg file, and I should pass the SnapIt app but I'm lazy and sloppy
    CaptureImage frmCurrent.Hwnd, frmCurrent.Name

    'Close the form without saving any change
    DoCmd.Close acForm, frmCurrent.Name, acSaveNo

Next objCurrent

'Clean up the objects used
Set objCurrent = Nothing
Set frmCurrent = Nothing
Set S = Nothing

End Function

Function FindHeight(frmInput As Form) As Double
'Access won't tell us how tall the whole form is for printing in
'Design view - We have to loop through the sections collection
'and add up each section's height (and the little dividing bar if there's
'more than one section) But wait, there's more! There IS NO SECTIONS
'COLLECTION. And there's no sections property to
'tell you how many sections there might be. So,
'we just loop through section(s) 'til it all blows up and stop.
Dim sctCurrent As Section
Dim intCount As Integer
Dim dblHeight As Double
Dim intDividerHeight As Integer

On Error Resume Next
Err.Clear

'We know there's a 0 section... there has to be
intCount = 0
dblHeight = 0    'This is zero first for 1 section forms
intDividerHeight = 0
Set sctCurrent = frmInput.Section(0)

Do
    dblHeight = dblHeight + sctCurrent.Height + intDividerHeight
    'We got Section(0) height, let's see if the next section blows up?!
    intCount = intCount + 1
    Set sctCurrent = frmInput.Section(intCount)
    'if we go on to the next section, we'll start adding divider bar height
    intDividerHeight = 300
Loop While Err.Number = 0 'keep looping until error

Set sctCurrent = Nothing

FindHeight = dblHeight
End Function

Sub CaptureImage(lngHwnd As Long, strFileName As String)
'Set up the image input options to capture a specific window
'by its windows window handle
S.Input = siiWindow
S.InputWindowOptions.SelectionMethod = swsmHandle
S.InputWindowOptions.Handle = lngHwnd
'Set up the output so that we get .jpgs with the name of the form
S.Output = SNAGITLib.snagImageOutput.sioFile
S.OutputImageFile.FileNamingMethod = sofnmFixed
S.OutputImageFile.FileType = siftJPEG
S.OutputImageFile.Directory = "C:\Documentation"
S.OutputImageFile.Filename = strFileName

'Don't show anything... just hammer through
S.EnablePreviewWindow = False
S.IncludeCursor = False
'This pulls the trigger on SnagIt after the options are set up
S.Capture

End Sub

 

References

Journal of Accountancy Articles

Tweaking The Numbers

Block That Spreadsheet Error

Excel Security Issues


 

Clients

Do you need help with Microsoft Office? Contact us

See how we've helped companies like yours develop effective business processes

Client Success Stories


 

Consultants

I Get It! Consultants set their own hours, work with their own clients, and choose their own projects.

If you're a Microsoft Office guru and would like to explore being a full-time consultant, please see our consultant information pages.