Kill All Pending Procedures

  • Thread starter Thread starter DavidW
  • Start date Start date
D

DavidW

Got a little problem with a report.
On the "No Data" Segment in a report, I put a code to close and prompt a
message if no data is present. In the report that has no data there is a
procedure in the "onclose" seqment to open another report, how do you kill
the procedure when the "nodata" takes command?
Thanks
David
 
DavidW said:
Got a little problem with a report.
On the "No Data" Segment in a report, I put a code to close and
prompt a message if no data is present. In the report that has no
data there is a procedure in the "onclose" seqment to open another
report, how do you kill the procedure when the "nodata" takes command?
Thanks
David

Probably the easiest thing to do would be to set a module-level flag
variable in the report's NoData event, and test this variable in the
report's Close event. Code could be similar to this:

'----- start of report's code module -----
Option Compare Database
Option Explicit

Dim mfNoData As Boolean

Private Sub Report_Close()

If mfNoData Then
' There was no data for this report.
Debug.Print "No data was reported."
Else
' There was data, so do something.
Debug.Print "Data was reported."
End If

End Sub

Private Sub Report_NoData(Cancel As Integer)
MsgBox "There's nothing to report!"
Cancel = True
mfNoData = True
End Sub
'----- end of report's code module -----
 
Hi,
You could have a module level variable (that means it's declared in the declarations
section of your report code module) that would indicate the 'no data'.

So if you called it:

Dim bNoData As Boolean

Then in the NoData event:
bNoData = True

Then in your Close event:
If Not bNoData Then
DoCmd.OpenReport .....
End If
 
Got it to work with one exception,
I get an error from the original code that opened the first report, it says
the open action was canceled, any way to get around this issue?
Thanks David
 
David,

Make this error happen again and note the error number it gives you

In your code for opening the first report modify it slightly to include
handling of this error. An example is as follows

Private Sub OpenMyReport
On Error Goto Err_OpenMyReport ' Enable error handler

' Code goes here to open report

Exit_OpenMyReport:
' Exit the sub normally
Exit Sub

' Error Handler
Err_OpenMyReport:
' Check which error occured
Select Case Err
Case 2085 ' Replace 2085 with the error number you got above
' Exit the sub and ignore message
Exit_OpenMyReport
Case Else
' Display the error to the user
MsgBox Err.Description, vbCritical, "Error " & Err
' Exit the sub
Exit_OpenMyReport
End Select
End Sub

Just replace OpenMyReport with your procedure name and 2085 with the error
number you got and it should work.

HTH,

Neil.
DavidW said:
Got it to work with one exception,
I get an error from the original code that opened the first report, it says
the open action was canceled, any way to get around this issue?
Thanks David
 
Back
Top