|
-
October 11th, 2009, 05:48 PM
#1
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")
-
October 12th, 2009, 12:47 AM
#2
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)
-
October 13th, 2009, 03:42 AM
#3
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|