Runtime Error 2501 on different device (1 Viewer)

jimbo92

New member
Local time
Today, 02:34
Joined
Oct 26, 2019
Messages
10
I have a working database on my computer that lets me add expense items, employees, work entries, etc., then output into reports (e.g. Employee Expense Report). Everything works fine on my computer, but when my friend tries to run reports on his Surface Pro, he gets a Runtime error 2501. Here is an example of the code generating the error:

Code Tags Added by UG

Code:
Private Sub EmpExpDown_Click()
    Dim fd As FileDialog
    Dim strFolder As String
    Dim sFilename As String
    sFilename = [EmployeeEntered] & " Expenses " & [EmpStartDate] & ".pdf"

    Set fd = Application.FileDialog(msoFileDialogFolderPicker)

    If fd.Show = -1 Then
    strFolder = fd.SelectedItems.Item(1)
    Else
    Exit Sub
    End If
  
    DoCmd.OutputTo acOutputReport, "Employee Expense Report", acFormatPDF, strFolder & "\" & sFilename, False
    Set fd = Nothing

End Sub

The line that appears to be causing the problem is:

DoCmd.OutputTo acOutputReport, "Employee Expense Report", acFormatPDF, strFolder & "\" & sFilename, False

The error occurs after he selects the folder to put the report in. Seems strange that the reports run just fine for me. Any ideas? I'm an Access noob.
 
Last edited by a moderator:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 01:34
Joined
Feb 28, 2001
Messages
27,001
Error 2501 says "Open Form or Report action was cancelled." Usually means that someone returned a TRUE to the Cancel variable that is the only call argument in the Form_Open event sequence. So at first blush, the question isn't what is wrong with your DoCmd sequence, it is whether there is possibly something in your report code. Look for a Report_Open event.

However, there is at least one other possibility. Is your friend trying to run the report ON the Surface Pro using a copy of the DB or is he accessing your system and trying to run the DB from your system disk but on his Surface Pro? That would make a difference because the second case could easily lead to a "Permissions" problem. Please clarify exactly how your friend is attempting to run this report.
 

jimbo92

New member
Local time
Today, 02:34
Joined
Oct 26, 2019
Messages
10
My friend has been using a copy of the file on his Surface Pro, not accessing it from my system. I tested it this same way on two more PCs now. It works perfectly on one of them, but the other one gets the same error.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:34
Joined
May 7, 2009
Messages
19,169
there are certain characters that are not allowed on naming filename. one of them is the "slash" (/).
make sure you format your datefield into something else (removing the slash).
 

CJ_London

Super Moderator
Staff member
Local time
Today, 06:34
Joined
Feb 19, 2013
Messages
16,553
is it possible there is a problem with the value of [employee entered]?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 01:34
Joined
Feb 28, 2001
Messages
27,001
OK, I propose a simple permissions test on any machine having this problem. You are selecting a particular folder from a list. Using Debug.Print, look at strFolder just before the DoCmd that opens the report. See what it says. Then manually concatenate strFolder with "\" and sFilename. Now see if you can create a file of that same exact specification with some other utility, or even just a COPY verb at the command prompt but for which the default directory is NOT the one specified by strFolder. See if you can create the file manually. If not, look at the error and figure out why. That will answer your question, perhaps.

If this works, then I would need to think about it some more.
 

jimbo92

New member
Local time
Today, 02:34
Joined
Oct 26, 2019
Messages
10
Ok, problem solved. @arnelgp had it right. The two computers I tested that it worked for had default Windows dates showing as "2020-02-11", whereas the two computers that it didn't work on had default date displays of "02/11/2020". So the "/"s were messing those up. Thanks everyone for the help!
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 01:34
Joined
Feb 28, 2001
Messages
27,001
Aha! A regional setting that is, of course, a per-computer choice. Makes PERFECT sense. Good catch, jimbo92.
 

Users who are viewing this thread

Top Bottom