Try to Print Report and Sometimes Form Prints

dgambale@gmail.com

Registered User.
Local time
Today, 12:08
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
 
Try open the report as Dialog.
Code:
DoCmd.OpenReport "rptquoteExtreme", acViewPreview, , "Quote_ID=" & Me.Quote_ID, acDialog
 
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
 
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,
 
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.
 
My apologies. I misunderstood the post.
 
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
 
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.
 
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...
 
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..
 
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
 
My apologies. I misunderstood the post.
Hi,

Same for me..

I know a really old thread but had this problem for years ,only a program I use once a year & just re-opening & closing jsut seems to work in the end but trouble is it waste the labels I am printing on, not just normal paper. This time I went hunting for a solution

I have a simple Menu Form, click a button & it opens the report below.
Absoluely no code on the report, preview is exactly the data I want, I zoom, scroll through the pages but often when I use the print icon or menu the underlying menu form is printed, very odd.

stDocName = "Labels ContactsGoogle Option"
DoCmd.OpenReport stDocName, acPreview, , Criteria

Adding, acDialog does fix but really would like to know why, one of those really annoying things.

Of course not urgent or important but if there were any ideas
 
Skipping used labels is easy enough with a little code in the label report. Here's the print form. It has a list box to select the labels. There is only one option in the sample. Then there is a box where you put in the number of labels to skip.

1734121247811.png


Here is the complete code module for the report. On open, the query associated with the label report selection is populated. Then in the Print event of the Detail section, you compare the number of labels from the form to the intBlankCount running count.
Code:
Option Compare Database
Option Explicit

    Dim intBlankCount As Integer


Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
         If intBlankCount < Forms!frmPrintLabels!txtSkip Then
            Me.NextRecord = False
            Me.PrintSection = False
            intBlankCount = intBlankCount + 1
         End If
End Sub

Private Sub Report_Open(Cancel As Integer)
    Me.RecordSource = Forms!frmPrintLabels!txtQueryDefName
End Sub
 

Users who are viewing this thread

Back
Top Bottom