Problem using command button to print

G

Gina Whipp

Hello All,

On my Main Menu you select a button which list all the reports (in a list
box). You can double click on a report name in the ListBox (located on the
Main Menu) and the report goes into preview and maximizes (and, yes I do
need it maximize):

Case "rpt"
DoCmd.OpenReport ObjectName, acViewPreview
DoCmd.Maximize
Case Else

However, if the report has no data, I am utilizing the Report_NoData to show
a message box informing you of that. BUT since the report doesn't open into
preview mode, the Main Menu (from where you selected the report) feels
compelled to maximize. I have tried everything I can think of to get the
Main Menu to remain it's designed size. Any ideas what I can do would be
greatly appreciated.

Thanks,
Gina
 
J

jl5000

Try this:

-Move the docmd.maximize to the On Open event of your report(s)
-Add docmd.restore code to the On Close event of your report(s)
 
G

Gina Whipp

I put it on the button because of the amount of reports. The button is on
the Main Menu. Placing DoCmd.Restore on the report does nothing, putting it
on the form causes the form to do this funky Maximize/Restore thingy on the
close of the report. (Just don't like the way that looks.)
 
U

UpRider

This code works perfectly for me for dozens of reports
Either blank or not.

UpRider

'Below code is if form module
Private Sub cmdRunReport_Click()
dim strDocName as string
strDocName = "rptQuickAudit"
DoCmd.OpenReport strDocName, acViewPreview
DoCmd.Maximize
DoCmd.RunCommand acCmdFitToWindow
End Sub

'Below code in report module
Private Sub Report_Close()
DoCmd.Restore
End Sub

Private Sub Report_NoData(Cancel As Integer)
MsgBox "This selection produces a blank report. Click OK to
cancel.", , _
"B L A N K R E P O R T"
Cancel = True
End Sub
 
G

Gina Whipp

For some reason it leaves my Main Menu maximized... What are the border
setting on your form, maybe that's my issue?
 
U

UpRider

Tried it both sizable and dialog, both worked same, OK
BTW, I do have an error procedure that ignores 2501 (you cancelled the
previous operation) error.

UpRider
 
G

Gina Whipp

Nope not on that form or on the report. Not sure where you wanted me to
find that. However, I am convinced it MUST be a setting on my Main Menu, so
the search begins...
 
G

Gina Whipp

Not sure how placing anything on the On_Close of the report does anything
when all I get is a message box telling you there is no information, the
report never really opens. It doesn't work for me anyway but just a
thought.
 
U

UpRider

Ah, but it does run its code. Where else does the Report_NoData msgbox
display come from? And the "cancel = true" will cause the Report_Close code
to run. Do you have this code in your reports?

UpRider
 
G

Gina Whipp

Yes, I have that code on the Report_NoData section... Oddly enough the
reports that have nothing in that section leave the Main Menu the preset
size. It's only the ones that have the NoData message box that maximize the
Main Menu. (Not sure I mentioned that before!) I also tried putting
DoCmd.Restore in that section, no go there either. This has me stumped!
 
G

Gina Whipp

That has already been done when the form was created... so I guess I'm on
my own :eek:( Thanks anyway!
 
Top