Run-time error 2501

Tophan

Registered User.
Local time
Today, 13:52
Joined
Mar 27, 2011
Messages
389
Hello. I have suddenly been getting a run-time error on a report I have been running for the past two years without issue. The code would create the report, save it to the specified file path and name the report based on a data entered in a particular field. This was working fine up until December and now it hasn't worked properly for the year.

Code:
Private Sub CmdPrintTender_Click()
Dim strWhere As String
   
      If Me.Dirty Then    'Save any edits.
          Me.Dirty = False
      End If
   
      If Me.NewRecord Then 'Check there is a record to print
          MsgBox "Select a record to print"
      Else
          strWhere = "[PW_No] = """ & Me.[PW_No] & """"
          DoCmd.OpenReport "RPTProspectiveWorks", acViewPreview, , strWhere
      End If
   
  Dim FileName As String
  Dim FilePath As String
   
  FileName = Me.TenderNo & " - " & Me.ProjectName
  FilePath = "J:\Tender Detail Forms\" & FileName & ".pdf"
 [COLOR="Red"] DoCmd.OutputTo acOutputReport, "RPTProspectiveWorks", acFormatPDF, FilePath
[/COLOR]  MsgBox "Tender Detail Form has been successfully created and saved to J:\Tender Detail Forms", vbInformation, "Enter Tender Details"

End Sub

The text in red is what is highlighted in the error. I have tried compacting and repairing the db, updating my Adobe license and even uninstalling and reinstalling both programmes. The file path hasn't changed and I haven't had to do any maintenance to the db in almost a year...everything was working just fine.

Any suggestions what else to look for?
 
Add a
Debug.Print FilePath
Before your final output command - I suspect the data is at fault.

The full path will be displayed in the immediate window (Press ctrl + g) when the VBA editor debug window comes up.
 
Oh my goodness! I followed your instructions and the error was so simple I am almost embarrassed to let you know.

The project I am currently working on, since the start of the year, has a forward slash (/) in the project name. So I have been updating the data all month long and frustrating myself when I keep getting an error message when I run the report.

Only just now when I ran the Debug.Print FilePath and examined what the file name is in the intermediate window did I spot the error.

Can't believe I even went so far as to uninstall and reinstall both Adobe and Access.

Thank you so much for your help
 

Users who are viewing this thread

Back
Top Bottom