Sandeep Thomas
Sandeep Thomas

Reputation: 4759

Outlook Mail sending triggers error even after mail being sent successfully

I'm trying to integrate Outlook in VBA. So I did a sample code in a button click as follows.

Private Sub CommandButton1_Click()
On Error GoTo ErrHandler
    Dim objOL As New Outlook.Application
    Dim objML As Outlook.MailItem
    Set objML = objOL.CreateItem(olMailItem)
    With objML
        .to = "[email protected]"
        .Subject = "This is a test message from Sandeep Thomas via VBA"
        .Body = "Hi there"
        .Send
    End With
    Set objOL = Nothing: objML = Nothing
Done:
    Exit Sub

ErrHandler:
    MsgBox "Error " + Err.Description
End Sub

But Im keep getting this message "The Item has been moved or deleted" even after the mail reaches the inbox. I didnt get what I did wrong.

Upvotes: 1

Views: 67

Answers (1)

Egan Wolf
Egan Wolf

Reputation: 3573

Try this:

Set objOL = Nothing: Set objML = Nothing

Upvotes: 2

Related Questions