Try to Print Report and Sometimes Form Prints (1 Viewer)

dgambale@gmail.com

Registered User.
Local time
Today, 14:51
Joined
Jul 31, 2013
Messages
19
Hello,

I have an Access 2013 database with linked tables to Sharepoint. On several forms I have a button that when clicked, it shows the record in the report as preview. The code I use is as follows for the button on the form.

Me.Refresh
DoCmd.OpenReport "rptquoteExtreme", acViewPreview, , "Quote_ID=" & Me.Quote_ID
Application.DoCmd.SelectObject acReport, "rptquoteExtreme"

When the user clicks the print button (to save as a PDF) from the ribbon in the Report, most of the time it works as expected.....However sometimes all the records from the original form prints instead of the specific record from the report as shown. To fix it, users have to close access and reopen and it seems to oddly work...most of the time.

I tried adding focus to the report by the last line of code but it made no difference. Any suggestions would be greatly appreciated....Im baffled.

Dean
 

JHB

Have been here a while
Local time
Today, 19:51
Joined
Jun 17, 2012
Messages
7,732
Try open the report as Dialog.
Code:
DoCmd.OpenReport "rptquoteExtreme", acViewPreview, , "Quote_ID=" & Me.Quote_ID, acDialog
 

dgambale@gmail.com

Registered User.
Local time
Today, 14:51
Joined
Jul 31, 2013
Messages
19
Thanks for the reply,

I will give it a try and let you know how it works....But why acdialog? What are you thinking? Why would that help? Im not familiar with the details of the command.

Thanks again
Dean
 

MarkK

bit cruncher
Local time
Today, 11:51
Joined
Mar 17, 2004
Messages
8,178
You are making the claim that DoCmd.OpenReport sometimes opens a form, which is very, very unlikely. It is far more likely that you have made a mistake in your observation. You say, "On several forms I have a button that when clicked, it shows the record in the report as preview." What I suspect is that on one of these forms, you have code that runs something other than you expect. Look at all the code under all the buttons, and find the one that opens the form.

Hope this helps,
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 11:51
Joined
Aug 30, 2003
Messages
36,118
You are making the claim that DoCmd.OpenReport sometimes opens a form, which is very, very unlikely.

In the OP's defense, I don't believe that claim was made. The problem occurs "When the user clicks the print button (to save as a PDF) from the ribbon in the Report", specifically "sometimes all the records from the original form prints instead of the specific record from the report as shown".

Perhaps another way of stating it is that the wherecondition isn't being respected when printing as it was when previewing. User is looking at the correct record in preview mode, but that's not what prints. Is that a correct summary?

That all said, this is a stumper. I use whereconditions a lot and users have never complained about this. Can we clarify that the user is printing rather than creating a PDF? Not that it should matter.
 

MarkK

bit cruncher
Local time
Today, 11:51
Joined
Mar 17, 2004
Messages
8,178
My apologies. I misunderstood the post.
 

dgambale@gmail.com

Registered User.
Local time
Today, 14:51
Joined
Jul 31, 2013
Messages
19
Yes....Pbaldy you are correct. The code works as it should from the point of view that the report shows the correct records in the preview mode.

The problem is that when the print button form the default command ribbon is clicked, occasionally the underlying form is printed instead of the report that is shown.

This is the mystery....Why is the underlying form being printed (OCCASIONALLY) and not the viewed report. I would say the report prints 95% of the time correctly.

To clarify the user is prints to PDF all the time.

Dean
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 11:51
Joined
Aug 30, 2003
Messages
36,118
Further clarification, since I'm completely stumped. Is it the form being printed (output), or the report but with all records? You can typically tell when a form is printed because the formatting is not as clean when printing a report.
 

dgambale@gmail.com

Registered User.
Local time
Today, 14:51
Joined
Jul 31, 2013
Messages
19
So when the report is shown and the button is click on the ribbon, the report should print 1 record in a formatted way.

A clue to this mystery is that to get to the report, a button on the form must be clicked that then opens up the REPORT to that one record.

When the printing error occurs, each record of the original form (where the button is used to open the report) is printed. So if the form has 100 records, the error will print all 100 records (unformated) of the FORM where the button to open the report is.

If it prints correctly the nice formatted REPORT will print one record as shown.

In ALL cases the report opens correctly and shows the one record it should print. 5% of the time, it prints all the records from the form instead.

Any suggestions are greatly appreciated...
 

JHB

Have been here a while
Local time
Today, 19:51
Joined
Jun 17, 2012
Messages
7,732
Thanks for the reply,

I will give it a try and let you know how it works....But why acdialog? What are you thinking? Why would that help? Im not familiar with the details of the command.

Thanks again
Dean
Did you try it my solution from post #2?
When you open it as dialog, then you're sure the focus will stay on the report and not by accident set back to the form.
Do you've more code behind the button from where you open the report, then show it.
Details of commands, you can find them in the MS-Access Help file..
 

dgambale@gmail.com

Registered User.
Local time
Today, 14:51
Joined
Jul 31, 2013
Messages
19
JHB,

I have tried the solution over the past few days of setting the report to open as a dialog box and it seems to work.

Its does indeed for the focus to the report as I must right-click on the report to print. Have not seen the seemingly random error of print the form since.

Thank you for the suggestion.

Dean
 

Users who are viewing this thread

Top Bottom