Error when trying to forward current email item

reubendayal

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Exchange Server 2013
Hi All,

I have created the below macro with all the wonderful posts from the Sliptick.com site, to use the current email in the active explorer and forward it with slight changes in the subject line and adding a message to the specific receivers.

But I seem to be receiving an error message each time I run this code and then after I select the debug option in the error message, and run the macro again, the macro works.

Code:
Public Sub ApprovalUpdate()


Dim objItem As Outlook.MailItem
Dim omail As Object
Dim NewEmail As MailItem
Dim Remail, AprMsg, Emsg, Remail2, Family As String
Dim NB, NB2 As Boolean

'***
'several steps to show a form for the user to insert/select specific info to include in the email message, etc.
'And IF statements that collect the right information to put in the email - All working well'
'****

Set objItem = GetCurrentItem()

Set omail = objItem.Forward

Set NewEmail = objItem.Forward

With NewEmail

    ....do whateever....
    .Body = Emsg & .Body
    .Recipients.ResolveAll
    .Display 'Send
End With

Unload ApprovalReceivers

Set objItem = Nothing
Set NewEmail = Nothing
Set omail = Nothing

MainAppl = ""

End Sub


Function GetCurrentItem() As Outlook.MailItem
    Dim objApp As Outlook.Application
          
    Set objApp = Application
    On Error Resume Next
    Select Case TypeName(objApp.ActiveWindow)
        Case "Explorer"
            Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
        Case "Inspector"
            Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
    End Select
      
    Set objApp = Nothing
End Function
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
What line does it stop on?

I have 3 errors, 2 might be just because I don't have your full code. With all 3 commented out, it works.

With NewEmail

'....do whateever.... <<== is not commented out in the code you posted. Delete the line or comment it out.
.Body = Emsg & .Body
.Recipients.ResolveAll
.Display 'Send
End With

'Unload ApprovalReceivers <== I don't have this userform

Set objItem = Nothing
Set NewEmail = Nothing
Set omail = Nothing

'MainAppl = "" <<== don't know what this is, possibly something in the userform.
 

reubendayal

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Exchange Server 2013
What line does it stop on?

I have 3 errors, 2 might be just because I don't have your full code. With all 3 commented out, it works.

With NewEmail

'....do whateever.... <<== is not commented out in the code you posted. Delete the line or comment it out.
.Body = Emsg & .Body
.Recipients.ResolveAll
.Display 'Send
End With

'Unload ApprovalReceivers <== I don't have this userform

Set objItem = Nothing
Set NewEmail = Nothing
Set omail = Nothing

'MainAppl = "" <<== don't know what this is, possibly something in the userform.

Hi Diane,

Thank you for replying.

I am sorry I didn't explain the full code very well.

The error is Run-Time error '2287': Application-defined or object-defined error. And the error always stops at the line -
Set omail = objItem.Forward

And when I go in to the debugger, and hover the cursor on omail or NewEmail, it shows them to be = Nothing. But by then the macro has created a forward of the original email item, without making any of the changes I want it to do via the With statement. And while I am in the debugger, if I hit F5, the macro runs again, and this time it would execute just as planned and the new email (forward) is created just as planned.

So to my non programmer knowledge, it appears like in the first try NewEmail is Nothing, but when I rerun the macro in the debugger it sort of gets focus on the email again and works fine.

Thanks.

Reuben
 

reubendayal

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Exchange Server 2013
Hi Diane,

Thank you for replying.

I am sorry I didn't explain the full code very well.

The error is Run-Time error '2287': Application-defined or object-defined error. And the error always stops at the line -
Set omail = objItem.Forward

And when I go in to the debugger, and hover the cursor on omail or NewEmail, it shows them to be = Nothing. But by then the macro has created a forward of the original email item, without making any of the changes I want it to do via the With statement. And while I am in the debugger, if I hit F5, the macro runs again, and this time it would execute just as planned and the new email (forward) is created just as planned.

So to my non programmer knowledge, it appears like in the first try NewEmail is Nothing, but when I rerun the macro in the debugger it sort of gets focus on the email again and works fine.

Thanks.

Reuben
Note: a quick correction - it is Run-Time error '287'.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
i just noticed this:
Set omail = objItem.Forward

Set NewEmail = objItem.Forward


Remove the omail lines - you aren't using that object. It didn't cause any errors for me though.


When you hover over objitem, does it show the subject? If the macro stopped on set omail, newemail will be nothing.
Set objItem = GetCurrentItem()
 

reubendayal

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Exchange Server 2013
i just noticed this:
Set omail = objItem.Forward

Set NewEmail = objItem.Forward


Remove the omail lines - you aren't using that object. It didn't cause any errors for me though.


When you hover over objitem, does it show the subject? If the macro stopped on set omail, newemail will be nothing.
Set objItem = GetCurrentItem()
Tried that too... but the same result - Run-Time error '287' .
 

reubendayal

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Exchange Server 2013
Tried that too... but the same result - Run-Time error '287' .
I have a solution for the problems, finally!

I have two other macros in the "ThisOutlookSession", one is for the ReplyAll event and the other an oItem_Forward. And the item forward was triggering before the intended macro or something like that as at the end of that macro the clean up routine of setting the email object to nothing was the reason.

So I added a global integer in my other macro and added an If statement at the start of the Item.forward macro to exit sub on a certain value of the global integer.

And now my other macro seems to work as normal.

Thank you anyway Diane.
 
Thread starter Similar threads Forum Replies Date
A Run-time error '430' on certain emails when trying to set "Outlook.mailitem" as "ActiveExplorer.Selection.Item" Outlook VBA and Custom Forms 2
N Error 0x80090326 when trying to setup IMAP account on Outlook.com Using Outlook.com accounts in Outlook 1
C Error message when trying to send email using a distribution list Using Outlook 2
J Error message when trying to download attachments to e-mails Using Outlook 1
P Error when trying to open EMC and Powershell Exchange Server Administration 4
L Receive error message when trying to receive new emails Using Outlook 1
T Error code: Error Code OX800CCC7D. Can receive email but when trying to send email it goes to the ou Using Outlook 2
D Outlook 2003 is getting an error when trying to open an exchange 2010 mailbox Exchange Server Administration 5
A Outlook 2010 trying to create calendar/task entries generates error "Could not save item.The connect Using Outlook 2
B when trying to open a link in an incoming email, get an error, 'This operation has been canceled due to the restrictions in this computer...&quot Using Outlook 2
D when trying to get into outlook error message reads connection to microsoft exchange is unavailable. Using Outlook 4
M 'Unknown error' when trying to delete an email Using Outlook 3
A Outlook 2010 trying to create calendar/task entries generates error "Could not save item.The connect Using Outlook 1
Y Ideas: Insert an error code or give a short description of what you are trying to accomplish or fix.__ Using Outlook 1
B Trying to restore data in Outlook and I get an error message to update the profile but when I click OK it takes me right out Using Outlook 7
C Ideas: Insert an error code or give a short description of what you are trying to accomplish or fix.__ Using Outlook 1
G Script Error message when trying to print e-mails using Outlook Mail Using Outlook 2
E error code MAPI error 0x80040107. I'm trying to move email messages and email lists from my old MS Using Outlook 2
C Error code 0x8004210a when trying to send/receive mails in Outlook 2003 Using Outlook 2
T Getting an error message while trying to accept a meeting request Using Outlook 1
H error message when trying to open Hyper links Using Outlook 2
F Ideas: Insert an error code or give a short description of what you are trying to accomplish or fix.__ Using Outlook 2
S Error while trying for Configuring OUT Of Office from outlook client Exchange Server Administration 4
J error 0X800ccc90 when trying to send or receive mails in Outlook Using Outlook 1
L trying to load my archived emails into new outlook on new harddrive. error message says I do not have permission Using Outlook 2
1 I keep receiving synchronisation error messages when trying to upload my e-mails from windowslive onto outlook. (have received 1465 error alerts! Using Outlook 1
O Messaging Interface unknown error when trying to export pst files Using Outlook 4
D getting error 0X80040600 when trying to send and receive emails in Outlook 2007 Using Outlook 4
K Error after trying to remove server from DAG Exchange Server Administration 3
G error when trying to get my mail in Outlook Express "An unknown error has occurred. Account: 'pop.we Using Outlook 2
C Error when trying to select the Email Auto link option Using Outlook 2
G attendees getting error when trying to accept modified recurring meeting - "The operation failed. An Using Outlook 1
S Re: "McAfee anti-spam add-in" error received when trying to open outlook Using Outlook 9
C When trying to go to a link in my e-mail error message says "This operation has been cancelled due t Using Outlook 1
K “Outlook is trying to retrieve data..." error. Using Outlook 1
D Error message while trying to acivate a link in any e-mail , occuring in the last few days. Before this was working fine. Using Outlook 1
T I am trying to use Outlook 2000 for my e mails I can receive emails but not send I keep getting error massage unable to find WAB DLL for Windows Conta Using Outlook 1
S Error message when trying to receive email in Outlook 2003 Using Outlook 4
T I am trying to use the import/export feature for outlook 2010 but I get an error message that the profile is already in use. Using Outlook 2
O Error (0x8004010F) when trying to download the OAB Exchange Server Administration 25
T 2010 Office trying to link to very old email address...error Using Outlook 1
A I get the following error when trying to open a hperlink; 'The operation has been canceled due to restrictions in effect on this computer. Please Using Outlook 1
W error code 0x800CCC92 with emails. cant seem to send receive. have windows 7 and trying to use outlo Using Outlook 1
J error when trying to upgrade exchange 2010 to sp1 Exchange Server Administration 5
P Word experienced and error trying to open the file Using Outlook 2
V Getting error while trying to replicate in DC repadmin /syncall Exchange Server Administration 1
N When trying to open 2007 Outlook/Vista, I get the error message below. Have no clue what caused this but I did have a power outage before this happen Using Outlook 1
S Missing file error when trying to sync iphone 3gs Using Outlook 1
N Error message when trying to open Outlook 2007. Using Outlook 2
N Re: Error message when trying to open Outlook 2007. Using Outlook 1
Similar threads


















































Top