Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: Run code after a form print preview

Geek News

Run code after a form print preview
Macsmasher 11/18/2008 8:21:03 PM
Running Access 2003.

I have a form that I want to print preview. When I when I fire my code from
the cmd button, it works fine It calls a sub that positions the controls and
sets the color for printing. But upon closing the print preview, I need to
run another Sub to reset the colors and reposition the controls. The problem
is, there is no Event for returning from print preview in which to call the
subs. So, when I come back to the form, everything is messed up from the
print.

Here is my code that fires from the cmd button on the form:

Private Sub cmdPrint_Click()

PrepareToPrint True 'calls a sub that formats colors and backgrounds.
Call FormatPortrait 'positions controls on form for portrait printing
Me.Printer.Orientation = acPRORPortrait
Me.Printer.PaperSize = acPRPSLetter
DoCmd.OpenForm "frmDrawSummary", acPreview
PrepareToPrint False 'Turns off the formatting for printing.
Call FormatLandscape 'Reset form controls back to their original
positions

End Sub

Basically, the last two lines don't fire. I've tried placing them in other
form Events like got focus, activate, etc. to no avail.

Just a side note...if I just print a hard copy with [DoCmd.PrintOut
acPrintAll] instead of [DoCmd.OpenForm "frmDrawSummary", acPreview],
everything runs fine.

Any help would be muchly appreciated!

-Larry
Re: Run code after a form print preview
John W. Vinson <jvinson[ at ]STOP_SPAM.WysardOfInfo.com> 11/18/2008 8:57:39 PM
On Tue, 18 Nov 2008 12:21:03 -0800, Macsmasher
<Macsmasher[ at ]discussions.microsoft.com> wrote:


Why not just save the Form as a Report, set the report's properties and format
appropriately, and *print the Report*?

Forms are really optimized for on-screen use, not for printing; reports the
reverse. It's easier if you use the right tool for the job!

[Quoted Text]
>Running Access 2003.
>
>I have a form that I want to print preview. When I when I fire my code from
>the cmd button, it works fine It calls a sub that positions the controls and
>sets the color for printing. But upon closing the print preview, I need to
>run another Sub to reset the colors and reposition the controls. The problem
>is, there is no Event for returning from print preview in which to call the
>subs. So, when I come back to the form, everything is messed up from the
>print.
>
>Here is my code that fires from the cmd button on the form:
>
>Private Sub cmdPrint_Click()
>
> PrepareToPrint True 'calls a sub that formats colors and backgrounds.
> Call FormatPortrait 'positions controls on form for portrait printing
> Me.Printer.Orientation = acPRORPortrait
> Me.Printer.PaperSize = acPRPSLetter
> DoCmd.OpenForm "frmDrawSummary", acPreview
> PrepareToPrint False 'Turns off the formatting for printing.
> Call FormatLandscape 'Reset form controls back to their original
>positions
>
>End Sub
>
>Basically, the last two lines don't fire. I've tried placing them in other
>form Events like got focus, activate, etc. to no avail.
>
>Just a side note...if I just print a hard copy with [DoCmd.PrintOut
>acPrintAll] instead of [DoCmd.OpenForm "frmDrawSummary", acPreview],
>everything runs fine.
>
>Any help would be muchly appreciated!
>
>-Larry
--

John W. Vinson [MVP]
Re: Run code after a form print preview
Macsmasher 11/18/2008 9:39:01 PM
Hi John,

Under normal circumstances, I completely agree. But the form is dynamic
with User expandable child objects that expand and contract. Once the
desired level of detail is achieved, then the User prints the form.

-Larry

"John W. Vinson" wrote:

[Quoted Text]
> On Tue, 18 Nov 2008 12:21:03 -0800, Macsmasher
> <Macsmasher[ at ]discussions.microsoft.com> wrote:
>
>
> Why not just save the Form as a Report, set the report's properties and format
> appropriately, and *print the Report*?
>
> Forms are really optimized for on-screen use, not for printing; reports the
> reverse. It's easier if you use the right tool for the job!
>
> >Running Access 2003.
> >
> >I have a form that I want to print preview. When I when I fire my code from
> >the cmd button, it works fine It calls a sub that positions the controls and
> >sets the color for printing. But upon closing the print preview, I need to
> >run another Sub to reset the colors and reposition the controls. The problem
> >is, there is no Event for returning from print preview in which to call the
> >subs. So, when I come back to the form, everything is messed up from the
> >print.
> >
> >Here is my code that fires from the cmd button on the form:
> >
> >Private Sub cmdPrint_Click()
> >
> > PrepareToPrint True 'calls a sub that formats colors and backgrounds.
> > Call FormatPortrait 'positions controls on form for portrait printing
> > Me.Printer.Orientation = acPRORPortrait
> > Me.Printer.PaperSize = acPRPSLetter
> > DoCmd.OpenForm "frmDrawSummary", acPreview
> > PrepareToPrint False 'Turns off the formatting for printing.
> > Call FormatLandscape 'Reset form controls back to their original
> >positions
> >
> >End Sub
> >
> >Basically, the last two lines don't fire. I've tried placing them in other
> >form Events like got focus, activate, etc. to no avail.
> >
> >Just a side note...if I just print a hard copy with [DoCmd.PrintOut
> >acPrintAll] instead of [DoCmd.OpenForm "frmDrawSummary", acPreview],
> >everything runs fine.
> >
> >Any help would be muchly appreciated!
> >
> >-Larry
> --
>
> John W. Vinson [MVP]
>
Re: Run code after a form print preview
"Stuart McCall" <smccall[ at ]myunrealbox.com> 11/18/2008 10:44:00 PM
"Macsmasher" <Macsmasher[ at ]discussions.microsoft.com> wrote in message
news:278F9E8A-878D-4B4B-8D6A-CF8176E41A4A[ at ]microsoft.com...
[Quoted Text]
> Running Access 2003.
>
> I have a form that I want to print preview. When I when I fire my code
> from
> the cmd button, it works fine It calls a sub that positions the controls
> and
> sets the color for printing. But upon closing the print preview, I need
> to
> run another Sub to reset the colors and reposition the controls. The
> problem
> is, there is no Event for returning from print preview in which to call
> the
> subs. So, when I come back to the form, everything is messed up from the
> print.
>
> Here is my code that fires from the cmd button on the form:
>
> Private Sub cmdPrint_Click()
>
> PrepareToPrint True 'calls a sub that formats colors and
> backgrounds.
> Call FormatPortrait 'positions controls on form for portrait
> printing
> Me.Printer.Orientation = acPRORPortrait
> Me.Printer.PaperSize = acPRPSLetter
> DoCmd.OpenForm "frmDrawSummary", acPreview
> PrepareToPrint False 'Turns off the formatting for printing.
> Call FormatLandscape 'Reset form controls back to their original
> positions
>
> End Sub
>
> Basically, the last two lines don't fire. I've tried placing them in
> other
> form Events like got focus, activate, etc. to no avail.
>
> Just a side note...if I just print a hard copy with [DoCmd.PrintOut
> acPrintAll] instead of [DoCmd.OpenForm "frmDrawSummary", acPreview],
> everything runs fine.
>
> Any help would be muchly appreciated!
>
> -Larry

Paste this function into a standard module:

Public Function FormIsOpen(ByVal FormName$) As Boolean
'Returns True if form formname$ is open in form view
With CurrentProject.AllForms(FormName$)
If .IsLoaded Then
FormIsOpen = (.CurrentView > 0)
End If
End With
End Function

Then, in your code where you open the form for preview, follow it with this:

Do
DoEvents
Loop Until FormIsOpen = False
'Now reset colors, reposition etc.


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net