Printing Problem When Using OpenReport

R

ridgerunner

The code below is working great, except, when the switchboard manager is
open. Then using the menu bar for File, Print causes the switchboard manager
to print, instead of the report. I tried keeping the Form open but it makes
no difference. I also tried to set focus to the report, but I keep getting
error messages, most likely because I am sure how to do that.

Private Sub CmdOK_Click()
DoCmd.OpenQuery "qryRptStoreDate", acViewNormal, acEdit
DoCmd.OpenReport "RptInspStoreDate", acViewPreview
DoCmd.Close acForm, "fdlgRptStoreDate"
DoCmd.Close acQuery, "qryRptStoreDate"
End Sub


ridgerunner
 
N

NKTower

Is the query RptInspStoreDate the source for the report? If so, I don't
think that you really want to open the query as a standalone - let the report
do it internally.

To test, just comment out the two lines referencing the query by putting an
apostrophe at the far left of the line.
 
R

ridgerunner

That seems to have fixed the problem, at least using the database copy I have
this weekend. But, I do not understand why. Can you explain?
 
N

NKTower

Windows applications are event-driven. When you cause something to happen,
such as click a button, code is executed and runs until completed. Windows
applicaoitns then wait for another event. In your case, the event was to
open the query (fine, but not needed, I'll explain in a minute), then open
the report (again, fine, this time what you really wanted) but then you were
under the assumption that the close of the query would happen when the report
was closed. Not so - it happened as soon as the report open was completed.
Having opened the report, VBA then went on to closing the query. This had
the side effect of wresting focus away from the report and returning it to
your form. So your PRINT request was captured by the form, not the report.

If, for example, you really want something to happen when the report is
closed, such as, say, marking records as having been viewed/printed, or
similar - then you should do that in the reports Report_Close() event.

The question then boils down to why you thought it necessary to open the
query. In design view it was prudent to check that the query returns the
records you want, all well and good. But in productionl because the report
was based on the query (my presumption that the query is named as the report
source) then report opens the query (invisibly) and uses it to populate the
report.
 
R

ridgerunner

Thank you for the great explanation. This is the first time I have attempted
to set up an application such as this and spent many hours reading and
studying about dialog boxes and trying to tie the query and the report all
together and make it all work. I think at one point in my attempts the
report did not populate with data unless I opened the query, but the need for
that apparently changed and I did not realize it. Thank for your help.

ridgerunner
 
R

ridgerunner

Here is an update on what happened with the "production" file. I made the
same changes to "comment out" the statements about the query and I continued
to have the same printing problem. Comparison of the two files showed me
that the production file had the popup property of the report set to "yes".
When I changed it to "no" the problem when away.
 

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