473,287 Members | 1,395 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

2501 Error Out put to Canceled

DJRhino1175
221 128KB
I get the 2501 error stating that the Out put to was canceled without anyone cancelling it. I go to debug and it points to lines 21 and 22.

I do not have any issues running this on my PC, but I have a user that gets this every time he try's to run this code.
I gave his PC full control of the folder the database is in thinking it was a rights issue but that did not help either.

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Option Compare Database
  3.  
  4. Private Sub btnMail1_Click()
  5.  
  6. Dim strEMail As String
  7. Dim oOutlook As Object
  8. Dim oMail As Object
  9. Dim strAddr As String
  10. Dim MyDB As DAO.Database
  11. Dim rstEMail As DAO.Recordset
  12. Dim strReportName As String
  13.  
  14. Set oOutlook = CreateObject("Outlook.Application")
  15. Set oMail = oOutlook.CreateItem(0)
  16.  
  17. strReportName = "New ECN Report"
  18.  
  19. gstrFilter = "[ECNID]=" & Me.ECNID
  20.  
  21. DoCmd.OutputTo acOutputReport, "rptECN", acFormatPDF, CurrentProject.Path & _
  22.                "\" & strReportName & ".pdf", , , , acExportQualityPrint
  23.  
  24. 'Retrieve all E-Mail Addressess in tblEMailAddress
  25. Set MyDB = CurrentDb
  26. Set rstEMail = MyDB.OpenRecordset("Select * From tblEMail", dbOpenSnapshot, dbOpenForwardOnly)
  27.  
  28. With rstEMail
  29.   Do While Not .EOF
  30.     'Build the Recipients String
  31.     strEMail = strEMail & ![EmailAddress] & ";"
  32.       .MoveNext
  33.   Loop
  34. End With
  35. '--------------------------------------------------
  36.  
  37. With oMail
  38.   .To = Left$(strEMail, Len(strEMail) - 1)        'Remove Trailing ;
  39.   .Body = "Please review the attached ECN and complete any and all tasks that pertain to you."
  40.   .Subject = Replace(Replace("ECNID |1: |2", "|1", Nz([ECNID], "")), "|2", Nz([NewPN], ""))
  41.     .Display
  42.   .Attachments.Add CurrentProject.Path & "\" & strReportName & ".pdf"
  43.  
  44. End With
  45.  
  46. Set oMail = Nothing
  47. Set oOutlook = Nothing
  48.  
  49. rstEMail.Close
  50. Set rstEMail = Nothing
  51.  
  52. Dim aFile As String
  53. aFile = "M:\Unsecure Share\New ECN System\New ECN Report.pdf"
  54. If Len(Dir$(aFile)) > 0 Then
  55.      Kill aFile
  56. End If
  57. End Sub
Jun 30 '22 #1

✓ answered by rachel gomez

The error 2501 can occur on calling On Close event of report, if there is a problem with the database. While working with reports and Forms error 2501 can be occur, if database go corrupted or changed. There are many reasons for this error like as row deletion in database or changed, data source key field is no longer primary key and relationships are gone, Network Connect Lost of data source etc.


Regards,
Rachel Gomez

0 11933

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: BlackSun | last post by:
most of my rpts don't open even in design mode open with VB gives 2501 error, that should be a sendobject error (related w email...) have you any clue? Access 2003
2
by: John Phelan-Cummings | last post by:
After creating a button on a (parent) form linking to another (child) form, I received the following error when clicking on the command button: "The OpenForm action was canceled" No the child...
33
by: Anthony England | last post by:
I am considering general error handling routines and have written a sample function to look up an ID in a table. The function returns True if it can find the ID and create a recordset based on...
8
by: sara | last post by:
I have a report that runs fine with data. If there is no data, I have its NO Data event sending a MsgBox and cancelling the report. Then it seems I still get the 2501 message on the Open Report...
1
by: wrcdc | last post by:
Hello. I have a form/radio buttons which chooses and action based on a chosen date from a combox box. Some of these options ask for a windows dialog box to choose input or output filename. All is...
2
by: dkohel | last post by:
What is wrong with the following code? I am trying to filter a form based on the selection of a combobox named cblPRD Dim currentFilter currentFilter = " = '" & Me!cboPRD & "'" Filter =...
7
sassy2009
by: sassy2009 | last post by:
Hello, I am running an insert query from xl spreadsheet using the DoCmd.RunSQL to insert values from the spreadsheet into the Access database. When i run this query it gives an error saying "...
1
by: Aftab Hussain | last post by:
I have following code for a start-up form: Private Sub Form_Timer() 'Close startup form and open logon form DoCmd.Close acForm, "Startup_Form" DoCmd.OpenForm "Logon_Form" End Sub And i am...
7
Brilstern
by: Brilstern | last post by:
This question is very similar to https://bytes.com/topic/access/answers/947462-access-2007-crashes-when-users-cancel-email-while-using-sendobject I am receiving a 2501 error when I cancel my...
1
by: dannymsa | last post by:
Hello, I am trying to a pply a filter on a access 2013 subform, from a query I created to filter data from a table. When I click the bottom to run the filter, I get the following error: ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.