|
Question : What would cause the Report_NoData Sub routine to run twice? Access 2003
|
|
I have the following code in a report as such:
Private Sub Report_NoData(Cancel As Integer) If bRptAll = False Then If MsgBox("No data for report - do you wish to view it anyway?", vbYesNo + vbQuestion) = vbNo Then Cancel = -1 End If End Sub
Everytime the report is ran - it asks the user twice if they wish to view it anyway when they select yes - why is that? Is there a particular glitch causing this?
To solve it this is what I"ve done in the following but there has to be a better way?
Option Compare Database Option Explicit
Private iTimes As Integer
Private Sub Report_NoData(Cancel As Integer)
iTimes = iTimes + 1 If bRptAll = False And iTimes = 1 Then If MsgBox("No data for report - do you wish to view it anyway?", vbYesNo + vbQuestion) = vbNo Then Cancel = -1 iTimes = 0 End If Else iTimes = 0 Exit Sub End If End Sub
Also what's interesting about this database is that its Access 2003 - converted from Access 97.
It has several reports which has images that are linked to various places on the internet. And when that report is ran there is some kind of dialog box trying to pull up the image which happens to be a .gif file on our network and it does exist.
|
|
Answer : What would cause the Report_NoData Sub routine to run twice? Access 2003
|
|
If your fix has stopped the problem and "Private iTimes As Integer" is in the report's object module, then I don't think it is the calling routine.
What is bRptAll and what does it do? Why are you asking the user if they want to see an empty report? The reason it asks twice is because when there is no data, the event is fired before the report starts to open. When you say yes, the report opens and fires the event again.
If you do want to give your users the option to see an empty report, I would do it this way.
Private Response As Boolean Response = Null 'If you do not initialize a variable, you are not guarranteed of its value
Private Sub Report_NoData(Cancel As Integer) If Response = vbYes Then Exit Sub If bRptAll = False Then Response = MsgBox("No data for report - do you wish to view it anyway?", vbYesNo + vbQuestion) If Response = vbNo Then Cancel = -1 End If End Sub
|
|
|
|