Solved How to remove this error "the execution this software stopped due to run time" error in MS Access VBA

nector

Member
Local time
Today, 08:10
Joined
Jan 21, 2020
Messages
494
I have configured the Gmail in MS Access 2016 with VBA and everything is work okay:
(1) I'm able to select recipients emails from the combo box
(2) I'm able to concatenate several emails automatically like we do it in outlook
(3) I have made both the attachment and CC as option all is working okay

Issues require your help

(1) I have this error after successfully succeeded sending an e mail : "execution this software stopped due to run time error"
(2) How to attach more than one attachment , is it possible

VBA Code used see below:

Code:
Private Sub Send_btn_Click()
'for early binding, enable tools > References > Microsoft CDO for Windows 2000 Library

Dim Newmail As Object
Dim mailConfig As Object
Dim fields As Variant
Dim msConfigURL As String

On Error GoTo Err1:
'late binding
Set Newmail = CreateObject("CDO.Message")
Set mailConfig = CreateObject("CDO.configuration")

mailConfig.Load -1
Set fields = mailConfig.fields

    With Newmail
        .Sender = DLookup("[EmailAddress]", "[tblSpecialcompanyDetails]", "[CompanyID] = 1")
        .From = DLookup("[CompanyName]", "[tblSpecialcompanyDetails]", "[CompanyID] = 1")
        .To = Me.SendTo
        .Subject = Me.Subject
        .TextBody = Me.Message
                       
        End With
If Not Attachment = "" Then
    With Newmail
        .AddAttachment Me.Attachment
    End With
    End If
   
If (Me.Cc <> "") Then
    With Newmail
        .Cc = Me.Cc
    End With
    End If
   

msConfigURL = "http://schemas.microsoft.com/cdo/configuration"
    With fields
        .item(msConfigURL & "/smtpusessl") = True 'enable the SSL authentication
        .item(msConfigURL & "/smtpauthenticate") = 1
        .item(msConfigURL & "/smtpserver") = "smtp.gmail.com"
        .item(msConfigURL & "/smtpserverport") = 465
        .item(msConfigURL & "/sendusing") = 2
        .item(msConfigURL & "/sendusername") = DLookup("[EmailAddress]", "[tblSpecialcompanyDetails]", "[CompanyID] = 1") 'input your gmail here
        .item(msConfigURL & "/sendpassword") = DLookup("[Password]", "[tblSpecialcompanyDetails]", "[CompanyID] = 1")
        .Update 'update the configuration fields
       
    End With
       
    Newmail.configuration = mailConfig
    Newmail.Send
    MsgBox "Your email has been sent.", vbInformation, "Your Email Has Been Sent Successfully"
    Me.Status = "Sent"
   
Exit_Err1:
'release object memory
Set Newmail = Nothing
Set mailConfig = Nothing
End
     
   
   
Err1:
    Select Case Err.Number
    Case -2147220973 'due to internet connection
    MsgBox "check your internet connection." & vbNewLine & Err.Number & ": " & Err.Description
   
    Case -2147220975 ' due to incorrect credentials
    MsgBox "Incorrect Credentials." & vbNewLine & Err.Number & ": " & Err.Description
   
    Case 13 'missing information
    MsgBox "Please fill up the required fiels." & vbNewLine & Err.Number & ": " & Err.Description
   
    Case -2146697203 'Invalid link for attachment
    MsgBox "Invalid Link for attachment"
       
        Case Else
        MsgBox "Error encountered while sending and email.", vbCritical, "Unsend"
       
        End Select
        Resume Exit_Err1

On Error Resume Next


End Sub


Email Error.png



VBA Reference.png


Both the error message and the VBA referencing is shown above, please note that the error does not affect the delivery of emails to the recipients, but I need to suppress that error
 
That error isn't being generated in your error handling routine - the text is a generic error message.
If it was we would see your msgbox.

So we need more accurate information.
I would turn off your error handler whilst debugging or return more information, like err.number, and err.description.
 
Issues require your help

(1) I have this error after successfully succeeded sending an e mail : "execution this software stopped due to run time error"
(2) How to attach more than one attachment , is it possible
1. Comment out the error handler, so you can debug the code when the error happens
2. Try repeating the code for multiple attachments
Code:
Attachments.Add Me.File1
Attachments.Add Me.File2
etc.
 
You probably don't have it set up for the type of troubleshooting you need. Open the VBA code window, then from the VBA window's menu bar:

Tools >> Options >> General

Check the "break on unhandled error" (temporarily) to see where the error occurs. Turn off / comment out your own error handling because your handler is essentially not doing anything useful. This is a DEBUGGING method that should be undone once you get it sorted out. But it might lead you to recognize other errors you would want to eventually include in your routine.

However, HINT: That message didn't come from the error routine in that code, not even from your "Case Else" catch-all option. Which means that the error was not in and/or was not called from your Send_btn_Click code.

The way that error handlers work, if some routine failed and you called that routine directly from your _Click code - and whatever you called didn't itself have an error handler - your error handler here would have tried to handle it. But that didn't appear to happen. Therefore, your problem is outside this code. The exception to my analysis is if you have a separate "helper" task - essentially like an application object - that croaked on you. Your handler wouldn't see that external task (if you had one). But I don't recall that CDO does that kind of thing, so call it an "unlikely" situation.

You are currently in the "catch the rabbit" mode and it will be hard to make headway until you can find that wascally widdle wabbit. (Sorry - too many Looney Toons cartoons as a kid...)
 
Is there any problem if I change the FE from accde to accdr. If leave the FE in this format accde , the above error does not come, but I want to try it again four times.

Commenting the error did not show any error in the code at all
 
The End statement in your code in the Exit_Err1 section terminates your application.
 
@sonic8 - good catch.

@nector - you have an END statement after your Exit_Err1 label and before your Err1 label. The effect of an END statement is that NOTHING gets compiled after that END. NOTHING in the module after that point has any effect whatsoever. Change it to EXIT SUB.

Not sure what performance effect that would have but whatever it does, it can't be good.
 

Users who are viewing this thread

Back
Top Bottom