Cosmos75
Registered User.
- Local time
- Yesterday, 19:26
- Joined
- Apr 22, 2002
- Messages
- 1,280
I have this code to save a snapshot file from a report in Access 97.
The problem I am having is that a snapshot file is created when there is no data in the report!
On all my reports I have this code to close report if there is no data to be shown.
Code:
Private Sub cmdSnapshotDateRange_Click()
On Error GoTo Err_cmdSnapshotDateRange_Click
'Check if date fields are empty
Call CheckDateRange
If DateRangeProblem = True Then
Exit Sub
End If
'Check is a report is seleted from combobox
If IsNull(Me.cboRPTDateRange.Column(1)) Then
MsgBox "Please select a report...", vbCritical, "No report selected!"
Me.cboRPTDateRange.SetFocus
Exit Sub
End If
Dim db As Database
Set db = CurrentDb()
Dim stDocName As String
Dim StartDate As Date
Dim EndDate As Date
Dim ReportDesc As String
Dim FileName As String
Dim SavePath As String
StartDate = Format(Me.txtStartDate, "mm-dd-yyyy")
EndDate = Format(Me.txtEndDate, "mm-dd-yyyy")
'Name of report in Access
stDocName = Me.cboRPTDateRange.Column(1)
'Description of report
ReportDesc = Me.cboRPTDateRange.Column(2)
'Name of saved file
FileName = ReportDesc & " for " & Format(StartDate, "mm-dd-yyyy") &_
" to " & Format(EndDate, "mm-dd-yyyy")
'Path to save file to
SavePath = Left(db.Name, Len(db.Name) - Len(Dir(db.Name)))_
& "Reports\"
MsgBox "File will be saved as " & FileName & ".snp in " & SavePath
'Save Snapshot file
DoCmd.OutputTo acReport, stDocName, "SnapshotFormat(*.snp)",_
SavePath & "" & FileName & ".snp", True
Exit_cmdSnapshotDateRange_Click:
Exit Sub
Err_cmdSnapshotDateRange_Click:
'Err 2501 returned when report has no data and is closed with [b]Cancel = True[/b]
If Err.Number = 2501 Then
Resume Exit_cmdSnapshotDateRange_Click
Else
MsgBox Err.Number
MsgBox Err.Description
Resume Exit_cmdSnapshotDateRange_Click
End If
End Sub
The problem I am having is that a snapshot file is created when there is no data in the report!
On all my reports I have this code to close report if there is no data to be shown.
Code:
Private Sub Report_NoData(Cancel As Integer)
On Error GoTo ProblemMsg:
MsgBox "Report has no data.", vbInformation, "No Data!"
Cancel = True
ExitReportNow:
Exit Sub
ProblemMsg:
MsgBox Err.Number
MsgBox Err.Description
Resume ExitReportNow
End Sub
Last edited: