Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

runtime error 2501 occurs on one client computer only. 2

Status
Not open for further replies.

edwilli

Programmer
May 22, 2003
33
US
I have a simple form in an Access Project (2003) where a user selects a value from a dropdown list and clicks "Submit"; which runs VBA code to open a report with the selected value used in the where clause. The form works perfectly on my computer and most client computers. However there is one client computer who consistently gets the "runtime error 2501" message when the VBA code tries to open the report. I'm guessing it may have something to do with macro security or maybe SP2, but I'm at a complete loss at what to do. The code is below for reference. Any help is appreciated.

Eric



Private Sub cmdSubmit_Click()

vWhere = "course_id = '" & CourseID & "'"
vReportName = "rptEvaluation"
'Open report if it is closed.
If CurrentProject.AllReports(vReportName).IsLoaded = False Then
DoCmd.OpenReport vReportName, acViewPreview, , vWhere '*****Code Fails Here*****
Else
'Close report and open it again.
DoCmd.Close acReport, vReportName
DoCmd.OpenReport vReportName, acViewPreview, , vWhere
End If
End Sub
 
I always put an error handler in any procedure that opens a report, since canceling the report generates the very common Err 2501:

Code:
Private Sub OpenReport()
On Error Goto ErrHandler

  [green]'code[/green]

ExitHere:
  Exit Sub
ErrHandler:
  If Err.Number <> 2501 Then
    MsgBox "Error Occurred"
  End If
  Resume ExitHere
End Sub

You should also code the Report_NoData() event for each report so the user knows there wasn't any data for the report, something like:
Code:
Private Sub Report_NoData(Cancel As Integer)
  MsgBox "No data matched your criteria", vbInformation, "No Data"
  Cancel = True
End Sub

VBSlammer
redinvader3walking.gif

"You just have to know which screws to turn." - Professor Bob
 
2501 is a common and tough error to resolve. Google for it to see.

You may find that the way you open the form with the Where clause may be partially at fault. For example, test and see if there are records to print before openning the report. Or use the FilterOption instead of the WhereOption.
 
The error handling tips do allow for a graceful exit. However the problem I'm having is that the 2501 error shouldn't be happening in the first place. The code works on all machines except one. I've googled other threads that report similar problems, but up to now no one has reported a solution.
 
hi all
i have the same problem and strange twist to it - i get error 2501 only on one box (PC that runs Windows XP) only when sertain user is logged in
i loggin on that box and open the report - it is fine
my user logs in on another box - it is fine
we tryed everything including giving her new box and reinstalling all apps anew - same result - error 2501
the only glimps of light in this dark matter is that if i blow user profile and rebuild it - report opens fine for sometime (2-3 hours to a day) and then breaks again
it is just f........ bad
i have been bangign my head on it for weeks
any clues anybody?
will make a sacrifice in your honor
 
I had the same problem recently. THis resolved the isue.

ref: building/previewing/printing reports in Access 2003

Apparently, report related functinality (building/previewing/printing) in MS Access DBMS is directly effected by the way printing is set up on users PC. Printer that is set up as a default and its driver(s) may cause Access reporting to break!

It has been noticed that combination of MS Windows XP Professional OS, Office 2003 (Access 2003), and HP LaserJet 5/5M printer was causinf break down of reporting. In Windows 2000 Professional environment with the same Office and Printer versions/models/setups reporting was stable and functining properly.

While in the process of installing new driver(s) for HP LaserJet 5/5M printer trivial manipulation with default printers was suggested and "fixed" user with report accessing.
HP LaserJet 4100 PCL 6 network printer was installed on user box and set up as adefault.
After previewing the report in Access user was able to Print the report to the original printer
(in pPrint dialog select another - not default - printer).

We expect the problem to be fixed permanntly after installing appropriate/new driver(s) for
HP LaserJet 5/5M printer on user PC.
 
My user was connected to an HP LaserJet 5 as well. Great job of sleuthing Vitamin!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top