Results 1 to 7 of 7

Thread: Outlook add in: Saved email gives error "Object reference not set..."

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2009
    Posts
    16

    Outlook add in: Saved email gives error "Object reference not set..."

    Hi
    I am creating a new email in Outlook 2007 using an VS2008 add-in, and save it to local disc.

    It creates the new Mailitem, saves it as MSG, and I can open it from local disc (by double clicking on file c:\temp.msg) while outlook is still open.

    When I close outlook, and then try to open the file from disc (by double clicking on the file c:\temp.msg), it does show the email message, BUT with an error messagebox saying : "Object reference not set to an instance of an object."

    Anyone have an idea what could be wrong?

    Code:
    Imports Microsoft.Office.Interop.Outlook
    Public Class save_message
    
    Private Sub btn_send_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_send.Click
    
    Dim oApp As Outlook.Application
    Dim oMsg As Outlook.MailItem
    oApp = New Outlook.Application()
    oMsg = oApp.CreateItem(Outlook.OlItemType.olMailItem)
    With oMsg
        .To = "[email protected]"
        .Subject = "this is the subject"
        .Body = "this is the body"
    End With
    oMsg.SaveAs("c:\temp.msg", OlSaveAsType.olMSG)
    
    End Sub

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Outlook add in: Saved email gives error "Object reference not set..."

    When you open a mail directly from the desktop, I doubt the btn_send_Click event fires...

    Can I see the code for the rest of the Addin?

    Also when you get this error, Which line does it highlight, in case you debug it?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2009
    Posts
    16

    Re: Outlook add in: Saved email gives error "Object reference not set..."

    Hi
    Ok I will expand a bit.

    I created an add-in which pops up a Windows form within outlook on startup.
    In this windows form I have a button called "btn_send", and contains the above code.

    When I click the send button, it saves a *.MSG file on my disk.
    I can open this file manually browsing to c:\temp.msg and doubleclicking on this file, no errors. All is good.

    BUT, whenever I close Outlook, and try to manually open the c:\temp.msg file from explorer, it gives the error "Object reference not set..."


  4. #4
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Outlook add in: Saved email gives error "Object reference not set..."

    Attach the addin, let me test it for you. I am more curious on the application open event...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 2009
    Posts
    16

    Re: Outlook add in: Saved email gives error "Object reference not set..."

    It is attached.

    This addin creates a GOGO shortcut under outlook's FILE> menu.
    when clicked it opens the windows form.
    Attached Files Attached Files
    Last edited by 3kwartappel; Jul 29th, 2010 at 05:35 AM.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Nov 2009
    Posts
    16

    Re: Outlook add in: Saved email gives error "Object reference not set..."

    hold on i think i found my problem, will report back just now

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Nov 2009
    Posts
    16

    Re: Outlook add in: Saved email gives error "Object reference not set..."

    Ok looks like it is because of a "catch ex as exception" section i had in This.Addin.vb
    Outlook didnt give an error on compile, but it doesnt like to catch as exception, or im doing something wrong.

    if i try
    Code:
    Try
    Catch ex As Exception
    End Try
    in form1.vb, outlook gives this error:
    Catch cannot catch type microsoft.office.interop.outlook.exception because it is not system.excetion or a class that inherits from system.exception
    so i removed the TRY from ThisAddIn.VB , now the email opens up without trouble.

    Thanks koolsid fom helping me find my problem.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width