Run code after a form print preview

M

Macsmasher

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
 
J

John W. Vinson

On Tue, 18 Nov 2008 12:21:03 -0800, Macsmasher


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
 
M

Macsmasher

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 said:
On Tue, 18 Nov 2008 12:21:03 -0800, Macsmasher


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
 
S

Stuart McCall

Macsmasher said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top