Printing Report Linked to a form - Errors

khwaja

Registered User.
Local time
Tomorrow, 10:28
Joined
Jun 13, 2003
Messages
254
I use the following code to print a record while in the form view using a command button which triggers a report for a matching record. Most of the time it works fine. Sometimes, however, a blank page is printed. My investigations indicated that there was an invisible form I use to detect idle time that is sometinmes selected as the current form.

The issue of printing a blank page only emerges when I am printing as PDF. Secondly, it is not just a brand new record causing the issue, this could be an old record I try to print and get a blank page. So the issue of commiting a record may not arise. Thirdly, as the form I am using is opened from a menu form, it is not only the detect idle time form but also the menu form that sometimes is printed. I can see these form names in the suggested name of file to be printed.

Is there a way I can ensure that only my currnt visible form is handled when I select the print option.

Private Sub cmdPrint_Click()
On Error Resume Next

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "rptCD"

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
stLinkCriteria = "[DocNo]=" & Me![DocNo]
DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria
DoEvents
DoCmd.RunCommand acCmdPrint
DoCmd.Close acReport, stDocName

Exit_cmdPrint_Click:
Exit Sub

Err_cmdPrint_Click:
End Sub
 
does your report have a "no data" event handler?
 
Yes, I do have something like this:

Private Sub Report_NoData(Cancel As Integer)
MsgBox "The report has no data." _
& "The requested report has been canceled. " _
& "Please check the criteria you have entered. ", vbOKOnly + vbInformation
Cancel = True

End Sub
 
and do you have any code in the "on load" event? if you are previewing the report first, and then switching views, for example, the report is not re-'loaded' but re-'formatted', so it might be an idea to throw that code in there...

another thing- you said this only happens when you print to PDF - how are you printing to PDF? are you using access' native PDF "Save As" function to print to PDF?

and when it prints a blank page, is it printing ONLY a blank page, or an EXTRA blank page in addition to what it's supposed to be printing?

- if you're using a third party PDF printer, i'd check suspicious settings too...

HTH
 
Thanks. No I don't have any thing on the on load event of the report. I am usug PDF driver that appears as one of the printers as part of the print dialogue box that appears as soon as a user hits the command button which has the code I have written above. So the print dialogue sits on top of the preview screen awaiting user input to select a printer including ADobe PDF as one of the option. Once user selects PDF option, I can see a network notification at the bottom of my screen showing a page is being printed. At that stage, if I see a little different name than I expect, e.g. detectidle or menu form, that is an indication that it is not going to print the report. That usually means a blank page is printed with a rectangle box shaded in top section of the page. I don't get an extra page. I am using prop Adobe software. Contrary to what I said before, it may not be PDF when I have the issue, it could happen when I am printing to my normal printers as well.
 
Just to make it easier, I have added a cut down version of the DB. This has the same functionality as original and intermittantly shows the issue I have. If you go to a pre filled in record after hitting the icon on the opening menu, and try to print several times, you will see that it sometimes prints a page that does not have the report in question. It is fairly intermittant so please try printing a few times.

Regards
 

Attachments

Users who are viewing this thread

Back
Top Bottom