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
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