I have a report that when opened goes striaght to the printer. When it is opened and there is no data then I get the error:
Run Time Error '2501':
The OpenReport action was cancelled.
However if I run the report in preview mode the code below works fine and a message box pops up like it should.
The question is how can I get the msgbox to pop up in acNormal like is does in Acpreview?
The following code is the only code in the report.
Run Time Error '2501':
The OpenReport action was cancelled.
However if I run the report in preview mode the code below works fine and a message box pops up like it should.
The question is how can I get the msgbox to pop up in acNormal like is does in Acpreview?
The following code is the only code in the report.
Code:
Option Compare Database
Private Sub Report_Open(Cancel As Integer)
Dim team_lead As String
Dim R_source As String
team_lead = DLookup("[team_lead_flag]", "qa_employee_list", "[userid] = '" & WinUser & "'")
If team_lead = "Y" Then
R_source = "SQL STATEMENT"
Else: R_source = "Another SQL Statement"
End If
Me.RecordSource = R_source
End Sub
Private Sub Report_NoData(Cancel As Integer)
MsgBox "There is no data for this report. Canceling report..."
Cancel = -1
End Sub