I have a report that is opened via a Form that lets the user choose a date to filter the report. The report opens in Print Preview mode.
What I'm attempting is to give the user an easy way to export the report once they've verified the report is accurate.
One way I've tried to do this was to use the OnClose event to execute a vbYesNo MsgBox giving them the option to export. The problem here is that I can't do the export while the report is closing.
I tried to move my MsgBox to the OnUnload so that could cancel the Unload, but was met with the same results. Code for that attempt follows:
Some research indicates perhaps the DoCmd.OutputTo is happening to quickly. Would including some type of pause in the code execution between the Cancel = True and the DoCmd solve my problem? Though frankly, even if it did it doesn't feel very elegant. I also recognize that I'd need to reinitiate the Unload>Deactivate>Close process after the export completed.
I've spent about the last 2 hours trying to figure this one out and I'm stumped.
I'm open to other suggestions to accomplish my goal. I initially began by having an Export Command Button on the form they use the choose a date, but was unable to have the exported report honor the user supplied filter from that form.
Here is the code from that form that is applying the filter:
What I'm attempting is to give the user an easy way to export the report once they've verified the report is accurate.
One way I've tried to do this was to use the OnClose event to execute a vbYesNo MsgBox giving them the option to export. The problem here is that I can't do the export while the report is closing.
Code:
Run-time Error '2585': This action can't be carried out while processing a form or report event.
I tried to move my MsgBox to the OnUnload so that could cancel the Unload, but was met with the same results. Code for that attempt follows:
Code:
Private Sub Report_Unload(Cancel As Integer)
Dim Response
Response = msgbox("Do you want to save a copy of this log?", vbYesNo, "Export to PDF")
If Response = vbYes Then
Cancel = True
DoCmd.OutputTo acOutputReport, "rptWatchLog", acFormatPDF
End If
End Sub
Some research indicates perhaps the DoCmd.OutputTo is happening to quickly. Would including some type of pause in the code execution between the Cancel = True and the DoCmd solve my problem? Though frankly, even if it did it doesn't feel very elegant. I also recognize that I'd need to reinitiate the Unload>Deactivate>Close process after the export completed.
I've spent about the last 2 hours trying to figure this one out and I'm stumped.
I'm open to other suggestions to accomplish my goal. I initially began by having an Export Command Button on the form they use the choose a date, but was unable to have the exported report honor the user supplied filter from that form.
Here is the code from that form that is applying the filter:
Code:
'Open Watch Log Report with chosen date as filter
Private Sub cmdOpen_Click()
'use date even though it's not saved anywhere
If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.OpenReport "rptWatchLog", acViewPreview, , "[EntryDate] = #" & Me.txtDate & "#"
DoCmd.Close acForm, "frmwatchlogdatepicker"
End Sub
'close the form w/o entering report
Private Sub cmdCancel_Click()
DoCmd.Close acForm, "frmwatchlogdatepicker"
End Sub