A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

EMail Send failure from Access



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old February 12th 08, 04:14 PM posted to microsoft.public.outlook.program_vba
Peter Hibbs
external usenet poster
 
Posts: 30
Default EMail Send failure from Access

Hi, first post to this NG so feel free to point me in the right
direction if this question is not appropriate.

Using Access 2003 (SP3) + Outlook 2003 (SP3)

I am using the following function to send an email from Access via
Outlook.
--------------------------------------------------------------------------------
Public Function SendMail(strRecipients As String, strSubject As
String, strBody As String) As String

'Entry (strRecipients) = Semicolon delimited string of recipients.
' (strSubject) = Required. Message subject.
' (strBody) = Optional. Body of the message.

Dim myObject As Object, myItem As Object
Dim vCount As Long

On Error GoTo ProcError

Set myObject = CreateObject("Outlook.Application")
Set myItem = myObject.CreateItem(0)
With myItem
.Subject = strSubject
.To = strRecipients

If Len(Trim(strBody)) 0 Then
.Body = strBody
End If
.Display
End With

ExitProc:
Set myItem = Nothing
Set myObject = Nothing
Exit Function

ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in SendMail Function..."
SendMail = "A problem was encountered attempting to automate
Outlook."
Resume ExitProc
Resume

End Function
--------------------------------------------------------------------------------

I am calling it like this from a button on a form :-
--------------------------------------------------------------------------------
Private Sub btnEMail_Click()

Dim vDummy As String

vDummy = SendMail("EMail Address here", "Subject", "Test")

End Sub
--------------------------------------------------------------------------------
The "EMail Address here" string is a valid email address.

The problem is that when I run the code, Outlook opens correctly
showing the email address, subject and body text but if I then Send
the email (or cancel the email by exiting Outlook) I get the following
error message on the .Display line.

Run-time error '-2147417851 (80010105) ':
Method 'Display' of object '_MailItem.' failed

Also Outlook is left running in the background, I have to close it
using Windows Task Manager.

The code Compiles with no errors and Compact & Repair and Decompiling
make no difference. I'm sure this worked OK a while ago (before or
loaded SP3) and I think the same problem occurs in Access 2000 (I'm
still checking that one as Outlook 2003 is being used as the email
client). References look OK, Outlook 11.0 Object Library is ticked
although I don't think it is necessary for this code.

If I open Outlook first and then send the email everything works OK,
the email gets sent and no error messages. It seems that Outlook does
not like the .Display command when it is not already loaded.

I have also tried using Redemption but get the same error message
(although I'm a bit unsure about the code here so that *may* be a bit
misleading).

Access NG have not come up with any clear solution, as yet.

Has anyone else come across the problem, could SP3 have broken
Outlook.

TIA

Peter Hibbs.
  #2  
Old February 13th 08, 05:59 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default EMail Send failure from Access



Does it work if you add this?

Dim Ns as Outlook.Namespace
Set myObject = CreateObject("Outlook.Application")
Set Ns=myObject.GetNamespace("Mapi")

--
Best regards
Michael Bauer - MVP Outlook
Use Outlook Categories? This is Your Tool:
http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6

Am Tue, 12 Feb 2008 16:14:31 +0000 schrieb Peter Hibbs:

Hi, first post to this NG so feel free to point me in the right
direction if this question is not appropriate.

Using Access 2003 (SP3) + Outlook 2003 (SP3)

I am using the following function to send an email from Access via
Outlook.

--------------------------------------------------------------------------------
Public Function SendMail(strRecipients As String, strSubject As
String, strBody As String) As String

'Entry (strRecipients) = Semicolon delimited string of recipients.
' (strSubject) = Required. Message subject.
' (strBody) = Optional. Body of the message.

Dim myObject As Object, myItem As Object
Dim vCount As Long

On Error GoTo ProcError

Set myObject = CreateObject("Outlook.Application")
Set myItem = myObject.CreateItem(0)
With myItem
.Subject = strSubject
.To = strRecipients

If Len(Trim(strBody)) 0 Then
.Body = strBody
End If
.Display
End With

ExitProc:
Set myItem = Nothing
Set myObject = Nothing
Exit Function

ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in SendMail Function..."
SendMail = "A problem was encountered attempting to automate
Outlook."
Resume ExitProc
Resume

End Function

--------------------------------------------------------------------------------

I am calling it like this from a button on a form :-

--------------------------------------------------------------------------------
Private Sub btnEMail_Click()

Dim vDummy As String

vDummy = SendMail("EMail Address here", "Subject", "Test")

End Sub

--------------------------------------------------------------------------------
The "EMail Address here" string is a valid email address.

The problem is that when I run the code, Outlook opens correctly
showing the email address, subject and body text but if I then Send
the email (or cancel the email by exiting Outlook) I get the following
error message on the .Display line.

Run-time error '-2147417851 (80010105) ':
Method 'Display' of object '_MailItem.' failed

Also Outlook is left running in the background, I have to close it
using Windows Task Manager.

The code Compiles with no errors and Compact & Repair and Decompiling
make no difference. I'm sure this worked OK a while ago (before or
loaded SP3) and I think the same problem occurs in Access 2000 (I'm
still checking that one as Outlook 2003 is being used as the email
client). References look OK, Outlook 11.0 Object Library is ticked
although I don't think it is necessary for this code.

If I open Outlook first and then send the email everything works OK,
the email gets sent and no error messages. It seems that Outlook does
not like the .Display command when it is not already loaded.

I have also tried using Redemption but get the same error message
(although I'm a bit unsure about the code here so that *may* be a bit
misleading).

Access NG have not come up with any clear solution, as yet.

Has anyone else come across the problem, could SP3 have broken
Outlook.

TIA

Peter Hibbs.

  #3  
Old February 13th 08, 12:10 PM posted to microsoft.public.outlook.program_vba
Peter Hibbs
external usenet poster
 
Posts: 30
Default EMail Send failure from Access

Michael,

Unfortunately not, the same error occurs. The code at the start of the
function looks like this now, I assume that is what you intended.
---------------------------------------------------------------------------
Public Function SendMail(strRecipients As String, strSubject As
String, strBody As String) As String

Dim myObject As Object, myItem As Object
Dim vCount As Long
Dim Ns As Outlook.Namespace

On Error GoTo ProcError

Set myObject = CreateObject("Outlook.Application")
Set Ns = myObject.GetNamespace("Mapi")
Set myItem = myObject.CreateItem(0)
.... continues as shown in original post.
--------------------------------------------------------------------------

Any other thoughts.

Peter Hibbs.

On Wed, 13 Feb 2008 06:59:48 +0100, "Michael Bauer [MVP - Outlook]"
wrote:



Does it work if you add this?

Dim Ns as Outlook.Namespace
Set myObject = CreateObject("Outlook.Application")
Set Ns=myObject.GetNamespace("Mapi")

  #4  
Old February 14th 08, 05:51 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default EMail Send failure from Access



Peter, I cannot reproduce that error. If I add a call to Logon:

Set Ns = myObject.GetNamespace("Mapi")
Ns.Logon

everything works fine.

--
Best regards
Michael Bauer - MVP Outlook
Use Outlook Categories? This is Your Tool:
http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6


Am Wed, 13 Feb 2008 12:10:30 +0000 schrieb Peter Hibbs:

Michael,

Unfortunately not, the same error occurs. The code at the start of the
function looks like this now, I assume that is what you intended.

---------------------------------------------------------------------------
Public Function SendMail(strRecipients As String, strSubject As
String, strBody As String) As String

Dim myObject As Object, myItem As Object
Dim vCount As Long
Dim Ns As Outlook.Namespace

On Error GoTo ProcError

Set myObject = CreateObject("Outlook.Application")
Set Ns = myObject.GetNamespace("Mapi")
Set myItem = myObject.CreateItem(0)
.... continues as shown in original post.
--------------------------------------------------------------------------

Any other thoughts.

Peter Hibbs.

On Wed, 13 Feb 2008 06:59:48 +0100, "Michael Bauer [MVP - Outlook]"
wrote:



Does it work if you add this?

Dim Ns as Outlook.Namespace
Set myObject = CreateObject("Outlook.Application")
Set Ns=myObject.GetNamespace("Mapi")

  #5  
Old February 14th 08, 09:44 PM posted to microsoft.public.outlook.program_vba
Peter Hibbs
external usenet poster
 
Posts: 30
Default EMail Send failure from Access

Michael,

Brilliant, that works perfectly. I still need to test it with multiple
recipients and attachments but I guess that should still work OK.

Not sure why adding the Logon function should make all the difference.

Hopefully it will work OK on my client's system (Access/Outlook 2000)
which I will check next week.

Anyway, thanks again.

Peter Hibbs.

On Thu, 14 Feb 2008 06:51:45 +0100, "Michael Bauer [MVP - Outlook]"
wrote:



Peter, I cannot reproduce that error. If I add a call to Logon:

Set Ns = myObject.GetNamespace("Mapi")
Ns.Logon

everything works fine.

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook 2003 stops Send/Recv on Login Failure John Kotuby[_2_] Outlook - General Queries 0 November 9th 07 01:14 PM
transfered pst files, but cannot access email address to send john skg Outlook - Using Contacts 3 November 16th 06 07:43 PM
Programmatically send Email text containing hyperlinks from Access momotaro Outlook and VBA 2 May 4th 06 08:44 PM
Send failure, notice keeps popping up keith Outlook Express 5 April 11th 06 12:01 AM
VBA Code to put in Access that will send an Email with Attachments [email protected] Outlook and VBA 1 April 9th 06 05:30 PM


All times are GMT +1. The time now is 06:05 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.