Define "completes successfully".
If you mean that the report arrived at the printer and printed all pages
without a paper jam or running out of ink or paper or having a user switch
the printer off in the middle of the print run, no: there is not a simple
way to determine the status of the printer and the jobs that have been
passed to its print queue, including knowing whether the job made it out of
the printer's memory and onto the paper.
If you just wanted to know if the report opened successfully, Access returns
Error 2501 if the report was cancelled by the user or its Open or NoData
event. The example below returns True if the report was opened, or False if
it was cancelled. It also solves a couple of other issues with reports, such
as the WhereCondition not being applied if the report is already open,
changing the default to preview, dumping the useless Filter argument, and
passing a meaningful description of the filter in OpenArgs so you can
display it on the report. (Only A2002 and 2003 have OpenArgs for reports.)
Function OpenTheReport(strDoc As String,
Optional lngView As AcView = acViewPreview, _
Optional strWhere As String, _
Optional strDescrip As String, _
Optional lngWindowMode As AcWindowMode = acWindowNormal) As Boolean
On Error GoTo Err_Handler
'Purpose: Wrapper for opening reports.
'Arguments: View = acViewPreview or acViewNormal. Defaults to
preview.
' strWhere = WhereCondition. Passed to OpenReport.
' strDescrip = description of WhereCondition (passed as
OpenArgs).
' WindowMode = acWindowNormal or acDialog. Defaults to normal.
'Return: True if opened.
'Notes: 1. Filter propery of OpenReport is not supported.
' 2. Suppresses error 2501 if report cancelled.
Dim bCancel As Boolean
Dim strErrMsg As String
'If the report is alreay open, close it so filtering is handled
correctly.
If CurrentProject.AllReports(strDoc).IsLoaded Then
DoCmd.Close acReport, strDoc, acSaveNo
End If
'Open the report
DoCmd.OpenReport strDoc, lngView, , strWhere, lngWindowMode, strDescrip
OpenTheReport = True
Exit_Handler:
Exit Function
Err_Handler:
Select Case Err.Number
Case 2501& 'Cancelled.
'do nothing
Case 2467& 'Bad report name.
MsgBox "No report named: " & strDoc, vbExclamation, "Cannot open
report."
Case Else
MsgBox "Error " & Err.Number & " - " & Err.Description
End Select
Resume Exit_Handler
End Function
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Bookreader" <Bo***********@yahoo.com> wrote in message
news:vl********************************@4ax.com...
Is it possible to return a code to Visual Basic when an Access reports
completes successfully and a different code when a report fails?
Thank you.