2501 Error - OpenReport Action Canceled.

J

Jani

Multiple users have a db but only one person is receiving the subject error.
I don't do much VB and the person that created the db is gone from the
company. Would someone be able to advise how this code should be fixed and
why only one person is having an issue with it. Thanks so much for your help!
Here's the code which I know is alot to wade through but I thought better to
include the whole thing rather than pick it apart and not have something that
is needed.

Function AvailDailyComparisonReport()
On Error GoTo 1
Dim rst As Recordset, counter As Integer
Dim startyear, startmonth As Integer
Set rst = CurrentDb.OpenRecordset("21DaysFromDateTo")
DoCmd.SetWarnings (WarningsOff)
' If Forms("frmReports").Daily Then - USED TO ALLOW DAILY COMPARISON OF
OEE COMPONENTS. ALTHOUGH THE REPORTS WERE ACCURATE - TOO CONFUSING - NOW ONLY
ALLOWING MONTHLY. Mark Smith 5/15/06
' DoCmd.OpenQuery "Clear21DaysFromDateTo"
' counter = 21
' Do
' rst.AddNew
' rst.Fields("Date").Value = month(Forms("frmReports").DateTo.Value
- counter) & "/" & day(Forms("frmReports").DateTo.Value - counter) & "/" &
year(Forms("frmReports").DateTo.Value - counter)
' rst.Update
' counter = counter - 1
' Loop Until counter = 0
' If Forms("frmReports").ExcludeNoDemand And
Forms("frmReports").ExcludeNoLabor Then
' DoCmd.OpenQuery "AvailCreateComparisonReportData - w/oNDw/oNL -
Daily"
' Else
' If Forms("frmReports").ExcludeNoDemand Then
' DoCmd.OpenQuery "AvailCreateComparisonReportData - w/oND -
Daily"
' Else
' If Forms("frmReports").ExcludeNoLabor Then
' DoCmd.OpenQuery "AvailCreateComparisonReportData - w/oNL -
Daily"
' Else
' DoCmd.OpenQuery "AvailCreateComparisonReportData -All -
Daily"
' End If
' End If
' End If
' DoCmd.RunMacro "TurnonWarnings"
' DoCmd.OpenReport "AvailComparisonReport - All - Daily", acPreview
' Else
Set rst = CurrentDb.OpenRecordset("12MonthsFromDateTo")
DoCmd.OpenQuery "Clear12MonthsFromDateto"
counter = 12
startmonth = month(Forms("frmReports").DateTo.Value)
startyear = year(Forms("frmReports").DateTo.Value) - 1
Do
If startmonth > 12 Then
startmonth = 1
startyear = startyear + 1
End If
rst.AddNew
rst.Fields("Date").Value = startmonth & "/" & "1" & "/" & startyear
rst.Update
counter = counter - 1
startmonth = startmonth + 1
Loop Until counter = 0
If Forms("frmReports").ExcludeNoDemand And
Forms("frmReports").ExcludeNoLabor Then
If Forms("frmReports").Shift.Value = "*" Then
If Forms("frmReports").ComparisonRow.Value = "shift" Then
DoCmd.OpenQuery
"QryAvailCreateComparisonTable-w/oNDw/oNL-Monthly-Shift"
Else
DoCmd.OpenQuery "AvailCreateComparisonTable - w/oNDw/oNL -
Monthly"
End If
Else
DoCmd.OpenQuery
"QryAvailCreateComparisonTable-w/oNDw/oNL-Monthly-Shift"
End If
Else
If Forms("frmReports").ExcludeNoDemand Then
If Forms("frmReports").Shift.Value = "*" Then
If Forms("frmReports").ComparisonRow.Value = "shift" Then
DoCmd.OpenQuery
"QryAvailCreateComparisonTable-w/oND-Monthly-Shift"
Else
DoCmd.OpenQuery "AvailCreateComparisonTable - w/oND -
Monthly"
End If
Else
DoCmd.OpenQuery
"QryAvailCreateComparisonTable-w/oND-Monthly-Shift"
End If
Else
If Forms("frmReports").ExcludeNoLabor Then
If Forms("frmReports").Shift.Value = "*" Then
If Forms("frmReports").ComparisonRow.Value = "shift" Then
DoCmd.OpenQuery
"QryAvailCreateComparisonTable-w/oNL-Monthly-Shift"
Else
DoCmd.OpenQuery "AvailCreateComparisonTable - w/oNL
- Monthly"
End If
Else
DoCmd.OpenQuery
"QryAvailCreateComparisonTable-w/oNL-Monthly-Shift"
End If
Else
If Forms("frmReports").Shift.Value = "*" Then
If Forms("frmReports").ComparisonRow.Value = "shift" Then
DoCmd.OpenQuery
"QryAvailCreateComparisonTable-All-Monthly-Shift"
Else
DoCmd.OpenQuery "AvailCreateComparisonTable - All -
Monthly"
End If
Else
DoCmd.OpenQuery
"QryAvailCreateComparisonTable-All-Monthly-Shift"
End If
End If
End If
End If
DoCmd.RunMacro "TurnonWarnings"
DoCmd.OpenReport "AvailComparisonReport - Monthly", acPreview
' End If
Exit Function
1
MsgBox "There was an error during the execution of the command. Error
code: (" & Error & "). Refer to OEE Database User's Manual or contact
database administrator if the problem persists.", vbCritical
Exit Function
End Function
 
K

Klatuu

Error 2501 means there is no data for the report.
The error can be eliminated by using the NoData event of the report to
present a message box and close the report. It is also necessary to trap for
the error in the error handler of the procedure that called the report. For
example, using your error handler it would be:

If err.Number <> 2501 then
MsgBox "There was an error during the execution of the command. Error
code: (" & Error & "). Refer to OEE Database User's Manual or contact
database administrator if the problem persists.", vbCritical
End if
 
J

Jani

Hi Klatuu - thanks for the quick reply. That's the strange thing - there is
data for this report and when I run the very same db on my laptop, same
criteria, same report, I do get a report with data. This person has Access
2003 but has SP2 loaded. Any ideas? Thanks, Jani
 
J

Jani

I will check with a couple others on their versions but it may take a day to
get back to you. This person can, however, export the data to Excel.
 
J

Jani

I've checked on two laptops and they each have exactly the same version (SP2)
as the person that is having issues. Any thoughts?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top