CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2009
    Posts
    2

    Outlook 429 error

    Hi there

    Im trying to create an app that send an email on button click, this only seems to work if outlook is closed.

    As this app will only be used when outlook is already open, it's not of much use to me at the moment.

    Error 429 shows when i click the send mail button: the code is as follow;

    Private Sub Command1_Click()
    Dim objOutlook As Outlook.Application
    Dim objOutlookMsg As Outlook.MailItem
    Dim objOutlookRecip As Outlook.Recipient
    Dim objOutlookAttach As Outlook.Attachment

    ' Create the Outlook session.
    Set objOutlook = CreateObject("Outlook.Application")

    ' Create the message.
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

    With objOutlookMsg
    ' Add the To recipient(s) to the message.
    Set objOutlookRecip = .Recipients.Add("[email protected]")
    objOutlookRecip.Type = olTo

    ' Set the Subject, Body, and Importance of the message.
    .Subject = "New A99 Call"
    .Body = Text3.Text
    .Importance = olImportanceHigh 'High importance

    ' Resolve each Recipient's name.
    For Each objOutlookRecip In .Recipients
    objOutlookRecip.Resolve
    Next

    ' Should we display the message before sending?
    If DisplayMsg Then
    .Display
    Else
    .Save
    .Send
    End If
    End With
    Set objOutlook = Nothing
    End Sub

    It's this line that seems to have the error: Set objOutlook = CreateObject("Outlook.Application")

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Outlook 429 error

    It's gotten harder and harder to send email by code. You are LATE-BINDING. You didn't say what version of OUTLOOK, or if it was EXPRESS (which doesn't work)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Nov 2004
    Location
    LA. California Raiders #1 AKA: Gangsta Yoda™
    Posts
    616

    Re: Outlook 429 error

    You are Early Binding since you have declared your object variables as a specified type and not as "Object".

    Here is my code integrated with yours.

    Ps, if you declare your object variables as "Object" instead, declare your constants and remove your reference to Outlook then you will be Late Binding and able to run with different versions of Outlook.


    Code:
    Option Explicit
    
    Private Sub Command1_Click()
       On Error GoTo MyError
    
       Dim objOutlook As Outlook.Application 'Object
       Dim objOutlookMsg As Outlook.MailItem 'Object
       Dim objOutlookRecip As Outlook.Recipient 'Object
       Dim objOutlookAttach As Outlook.Attachment 'Object
    
       'Get the Outlook session if Outlook is already running. It will goto MyError if not set
       Set objOutlook = GetObject(, "Outlook.Application")
       'Check if its set from resume next and create it
       If TypeName(oApp) = "Nothing" Then
          'Create a new instance of the Outlook application.
          Set objOutlook = CreateObject("Outlook.Application")
       End If
    
       ' Create the message. 
       Set objOutlookMsg = objOutlook.CreateItem(0) 'olMailItem
    
       With objOutlookMsg
          ' Add the To recipient(s) to the message.
          Set objOutlookRecip = .Recipients.Add("[email protected]")
          objOutlookRecip.Type = 1 'olTo
    
          ' Set the Subject, Body, and Importance of the message.
          .Subject = "New A99 Call"
          .Body = Text3.Text
          .Importance = 2 'olImportanceHigh 'High importance
    
          ' Resolve each Recipient's name.
          For Each objOutlookRecip In .Recipients
             objOutlookRecip.Resolve
          Next
    
          ' Should we display the message before sending?
          If DisplayMsg Then
             .Display
          Else
             .Save
             .Send
          End If
       End With
       Set objOutlook = Nothing
    
    MyError:
       'Test for the error being "Cant create object"
       If Err.Number = 429 Then
          'It is so lets return to the next line of code to create a new instance of the app object
          'Its possible that this could be executed twice if the CreateObject line fails
          'In which case that would mean the Office app is not installed or such.
          Resume Next
       Else
          'It was another type of error so lets display it to the user
          MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbExclamation
       End If
    
    End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda™)
    VB Forums - Super Moderator 2001-Present

    Microsoft MVP 2006-2011

    Please use [code]your code goes in here[/code] tags when posting code.

    Senior Software Engineer MCP, BSEE, CET
    VS 2012 Premium, VS 6.0 Enterprise SP6, VSTO, Office Ultimate 2010, Windows 7 Ultimate
    Star Wars Gangsta Rap SE Reputations & Rating Posts Office Primary Interop AssembliesAdvanced VB/Office Guru™ Word SpellChecker™.NETAdvanced VB/Office Guru™ Word SpellChecker™ VB6Outlook Global Address ListVB6/Crystal Report Ex.VB6/CR Print Setup Dialog Ex.

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

Featured