Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DB Documentation: How to print forms in design view

Status
Not open for further replies.

TheoCal

Vendor
Apr 30, 2003
5
0
0
US
Most 'flavors' of VB allow the printing of a form along with its VB code. Access does not since Access forms are not UserForms (part of access app, not VB Editor). Documentor does not print out forms. Trying desparately to avoid Snagit etc. screen capture software... I have scores of forms. Does anyone know of an automated way of printing forms in design view as part of a VB loop.
 
You can get the Properties and the Code easily enough using the Tools, Analyse, Documenter.

However, for an image of the actual form's layout I just hit 'PrintScreen' and then paste into Word.



'ope-that-'elps.



G LS
accessaceNOJUNK@valleyalley.co.uk
Remove the NOJUNK to use.
 
So, what I was trying to do was NOT have to open each of dozens and dozens of forms in design view, resize the windows, make a screen shot and then save the file with some horrible name like frmUserInputForProductEnhancements.jpg.

Then I realized just today that SnagIt (from supports VBA. Here's the code to do the rancid process above. Just make sure that the main Access window is maximized and that all other children windows are minimized. Hell, just close 'em all. Minimize the database window too. SnagIt will sometimes grab pieces of any windows that overlap your forms in Design view.

You need to have SnagIt of course. It must be version 6.2 or better. And you need to set a reference to the SNAGIT in VBA.

If you don't have and don't want snagit, you could use a windows call to printscreen and paste the clipboard into Word or something.

After this, I have an Adobe macro that looks for the form name in my code documentation and puts the identically named jpg just before it.

BTW, this is fun to watch run. I guess I amuse easily.

'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 CDoc()
Const HMARGIN_ERROR As Integer = 375
Const VMARGIN_ERROR As Integer = 625
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
'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 (add stupid. don't know how.)
CaptureImage frmCurrent.Hwnd, frmCurrent.Name

'Close the form without saving any changes
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 - bastards! 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. Double bastards! And there's no sections property to
'tell you how many sections there might be. Triple bastards! 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
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 goin' til you 'splode

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

'Not sure if I need this or not. They recommend it.
'Had some trouble with ActiveX server errors... best to wait I guess
'Maybe it's slow disk writes with the jpgs?
Do While Not S.IsCaptureDone
DoEvents
Loop

End Sub

Theo, I Get It!(r) Development
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top