Hi,
This is my first message on this forum, I will try to be as clear as possible.
I am trying to preview a report before printing it.
I want the user to:
1) Click on the button "Print report" on a form.
2) The report pops up in a print preview window
3) Just when the preview opens, I want a pop up to confirm printing. ("Yes" to print the preview and close it or "No" to just close the preview)
I have no issue with 1) and 2), but the printing confirm window appears before the preview is displayed, and blocks the operation. So I cannot actually preview the file before the printing confirmation.
This is the code from my "Print report" button on my form (I also tried with just report view and not preview, without success):
Code:
Private Sub cmdPrintReport_Click()
DoCmd.OpenReport "rptCardBack", acViewPreview, , , acDialog
End Sub
This is the code on my form, on open (I also tried on activate, page and load without success):
Code:
Private Sub Report_Open(Cancel As Integer)
If MsgBox("Do you want to print?", vbYesNo, "Print?") = vbYes Then
DoCmd.PrintOut
DoCmd.Close acReport, "rptCardBack", acSaveNo
Else:
DoCmd.Close acReport, "rptCardBack", acSaveNo
End If
End Sub
When I click "No" at the MsgBox, I get an error 2585 "This action can't be carried out whil processing a form or report event" linked to the piece of code that closes the report.
I do not have this error when I try to open the report on viewreport instead of viewpreview, but it still doesn't display the report!
I hope I was clear enough, but don't hesitate to ask for more information.
Thank you for helping me!
Nicolas