473,378 Members | 1,319 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,378 software developers and data experts.

2501 SendObject Error - Error Trapping Not Working

Brilstern
208 100+
This question is very similar to https://bytes.com/topic/access/answe...ing-sendobject

I am receiving a 2501 error when I cancel my sendObject cmd, which I have built error checking in for. When a user cancels the sending of an email, I receive the sendObject error twice and the application freezes. Once, which is not trapped and I can click Ok, and the second time, which my error checking traps. The issue is after I click ok on my own msgbox the application freezes and I have to close it from the taskman. Am I missing something here? It has to be simple and I am overlooking it.

Sub:
Expand|Select|Wrap|Line Numbers
  1. Private Sub emailReport_Click()
  2.  
  3. 'Run the Error handler "Errhandler" when an error occurs.
  4. Dim Action As Integer
  5. On Error GoTo ErrHandler
  6.  
  7.     If strReport = "" Then
  8.  
  9.         MsgBox "You don't have a report open, please regenerate the report", vbExclamation, "No Report Selected"
  10.  
  11.     Else
  12.  
  13.         Reports(strReport).Caption = "RMF Report"
  14.         DoCmd.SendObject acSendReport, strReport, acFormatPDF, , , , "Emailing RMF Report", , True, "RMF Report"
  15.  
  16.     End If
  17.  
  18.     Exit Sub
  19.  
  20. ErrHandler:
  21.  
  22.               ErrorHandling strNull, Err, Action
  23.  
  24.               If Action = Err_Exit Then
  25.                  Exit Sub
  26.               ElseIf Action = Err_Resume Then
  27.                  Resume
  28.               Else
  29.                  Resume Next
  30.               End If
  31.  
  32. End Sub
Error Checking:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. 'Declared Sub ErrorHandling
  3. Public Const Err_Exit = 0
  4. Public Const Err_Resume = 1
  5. Public Const Err_Resume_Next = 2
  6. Global strNull As String
  7.  
  8. Sub ErrorHandling(strNull As String, ErrorValue As Integer, ReturnValue As Integer)
  9.  
  10.    Dim Result As Integer, ErrMsg As String, Choices As Integer
  11.  
  12.    Select Case ErrorValue
  13.  
  14.       Case 68:     'Device  not available.
  15.  
  16.          ErrMsg = "The device you are trying to access is either " & _
  17.             "not online or does not exist. Retry?"
  18.          Choices = vbOKCancel
  19.  
  20.       Case 75:     'Path/File access error.
  21.  
  22.          ErrMsg = "There is an error accessing the path and/or " & _
  23.               "file specified. Retry?"
  24.          Choices = vbOKCancel
  25.  
  26.       Case 76:     'Path not found.
  27.  
  28.          ErrMsg = "The path and/or file specified was not found. Retry?"
  29.          Choices = vbOKCancel
  30.  
  31.       Case 94:     'No Value Selected.
  32.  
  33.          ErrMsg = "Please select a value."
  34.          MsgBox ErrMsg, vbOKOnly
  35.          ReturnValue = Err_Exit
  36.          Exit Sub
  37.  
  38.       Case 2501:   'Action Canceled
  39.  
  40.          ReturnValue = Err_Exit
  41.          Exit Sub
  42.  
  43.       Case Else:   'An error other than 68, 75,76, 94, 2501 or 3022 has occurred
  44.  
  45.          ErrMsg = "An unrecognized error has occurred ( " & _
  46.             Error(Err) & " ). The macro will end."
  47.          MsgBox ErrMsg, vbOKOnly
  48.          ReturnValue = Err_Exit
  49.          Exit Sub
  50.  
  51.    End Select
  52.  
  53.    'Display the error message.
  54.    Result = MsgBox(ErrMsg, Choices)
  55.  
  56.    'Determine the ReturnValue based on the user's choice from MsgBox.
  57.    If Result = vbOK Then
  58.       ReturnValue = Err_Resume
  59.    Else
  60.       ReturnValue = Err_Exit
  61.    End If
  62.  
  63. End Sub
  64.  
So to describe the steps.

I open a report to print preview and a small management form is opened up that allows me to email/save/print the form.

From that form I press an email button.
The email is generated and then the email pops up to allow the user to edit the email. If the user send the email. It works great.
If the user exits the email window they receive an initial error:

Title: The SendObject action was canceled.
Message: You used a method of the DoCmd object to carry out an action in visual basic, but then clicked cancelling a dialog box.
For example, you used the close method to close a changed form, then clicked cancel in the dialog box that asks if you want to save the changes you made to the form.

After I click ok, my error handling message appears for 2501 "Action Canceled"

Once I click ok here, there application is frozen and must be closed via taskman.
Aug 25 '16 #1
7 1660
Seth Schrock
2,965 Expert 2GB
Nothing is jumping out at me right away for why is is failing. Have you tried stepping through your code while checking values to see which line of code is locking up the program and what the variable values are at the time?
Aug 26 '16 #2
Brilstern
208 100+
Thanks for the look Seth. I have not, but I will do so today and report back.
Aug 26 '16 #3
ADezii
8,834 Expert 8TB
This is just my personal opinion, but I feel as though you need to capture Error 2501 at the point of origin (Click() Event of EMailReport Command Button) and NOT in a Customized Error Handling Routine. A simple execution of the displayed Code segment should prove/disapprove my idea. If I am incorrect, I do apologize for wasting your time.
Expand|Select|Wrap|Line Numbers
  1. Private Sub EMailReport_Click()
  2. On Error GoTo Err_EMailReport_Click
  3.  
  4. DoCmd.SendObject acSendReport, strReport, acFormatPDF, , , , "Emailing RMF Report", , True, "RMF Report"
  5.  
  6. Exit_EMailReport_Click:
  7.   Exit Sub
  8.  
  9. Err_EMailReport_Click:
  10.   Select Case Err.Number
  11.     Case 2501
  12.       'Ignore, no Message required (User Cancelled)
  13.     Case 68, 75, 76, 94, 3022
  14.       MsgBox Err.Description, vbExclamation, "Error in EMailReport_Click()"
  15.     Case Else
  16.       MsgBox "An Unrecognized Error has occurred!", vbExclamation, "Error Unrecognized"
  17.   End Select
  18.     Resume Exit_EMailReport_Click
  19. End Sub
Aug 26 '16 #4
Brilstern
208 100+
Checking now, never a waste of time ADezii . Always a learning experience.
Aug 26 '16 #5
Brilstern
208 100+
Unfortunately the same outcome. But, mainly because I have no personal attachment to SendObject I am moving to a late binding function and going to try that, still making some adjustments to some code that I dug up from a past project.

One thing to note:

When I open my application without allowing my AutoExec macro to run and hide my Access Window, remove shortcuts, etc. (holding shift) I can actually run the email function and cancel it just fine and the error is trapped. If I let the app run as normal (which locks down all user control to only what I have allowed) it gives the error which freezes the application. Not really sure why though...
Aug 26 '16 #6
ADezii
8,834 Expert 8TB
As a side note, if Outlook is your Default E-Mail Client, you can gain much greater flexibility using it to E-Mail the Report with either Early or Late Binding.
Aug 26 '16 #7
Brilstern
208 100+
I am using outlook, hence the late binding. But I am developing this for versatility so I prefer to stay away from early binding.
Aug 26 '16 #8

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

Similar topics

2
by: Myth of Sisyphus\). | last post by:
Hi, When trying to do a full backup, I get write on c\xxxxxxx\shipmatedb_20050715xxx - failed status 112. It allow however to do the backup is I select "overwrite existing media" The only...
3
by: windandwaves | last post by:
Hi Gurus Does anyone know how I set the error trapping to option 2 in visual basic. I know that you can go to tools, options and then choose on unhandled errors only, but is there a VB command...
13
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that works for me on the system I'm using, apparently...
3
by: SK | last post by:
Hi all, I am dealing with sockets in my code. I open them like - System.Net.IPAddress remoteIPAddress = System.Net.IPAddress.Parse (szIPSelected); System.Net.IPEndPoint remoteEndPoint = new...
1
by: Fred Nelson | last post by:
I'm devloping a VB.NET web application and I'm having a problem with trapping errors and logging the cause of them. In my web.config file I have the line: <customErrors ......
9
by: 47computers | last post by:
Pretty new to PHP, I recently started learning about error trapping. As of right now, I include the following into a page in my website: -------BEGIN PASTE-------- error_reporting(E_ERROR |...
25
by: James L Bryant | last post by:
At bootup this morning before displaying the Windows logo the following error string is displayed: Database corrupt.PsMain: 568c PsMain: 98bd PsMain: 9b45 PsMain: 49d6b PsMain: 3ca6f PsMain:...
1
by: SQACPP | last post by:
I have an error when compiling a simple form project... I just start a new Form project and add a new PictureBox in a form(or anything that generate the .resx file) After that when compiling I...
0
by: PW | last post by:
I have this line of code in our Access2003 application DoCmd.SendObject acSendReport, , acFormatRTF, strEmail, , , "Deposit Request" We have clients all over the country who execute this line of...
10
by: Basenji3 | last post by:
I have a statement that loops through a table to send a report via email. If I send all the emails it works fine, but if I cancel and email, I get the run-time error 2501 Can't sendobject. I have...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.