dbTalk Databases Forums  

Email attachment with CDO

comp.databases.ms-access comp.databases.ms-access


Discuss Email attachment with CDO in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Lou O
 
Posts: n/a

Default Email attachment with CDO - 11-07-2011 , 12:02 PM






I have been looking for a way to send an email from access with an
independent file attachment. In other words without using the
sendobject method which sends only access objects.
In this news group I came across the CDO Library method with very
simple code as below

Dim objMessage As New CDO.Message
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.From = "me (AT) my (DOT) com"
objMessage.To = "loosterhoff (AT) gmail (DOT) com"
objMessage.TextBody = "This is some sample message text."
objMessage.AddAttachment "c:\temp\readme.txt"
objMessage.Send

However the code generates the following error running the
Set......CreateObject line

Run-time error '-2147024770(8007007e)':
Automation Error
The specified module could not be found.

Does anyone know what this error means?
Am I missing a class module that this method requires?
I have a suspicion that it refers to MS Outlook (not installed) but
I'm not sure.

Thanks for your help
Lou O

Reply With Quote
  #2  
Old   
Tony Toews
 
Posts: n/a

Default Re: Email attachment with CDO - 11-07-2011 , 04:25 PM






On Mon, 7 Nov 2011 10:02:49 -0800 (PST), Lou O <lgeastwood (AT) gmail (DOT) com>
wrote:

Quote:
In this news group I came across the CDO Library method with very
simple code as below
Microsoft Access Email FAQ - CDONTS
http://www.granite.ab.ca/access/email/cdonts.htm

Beginning in Exchange Server 2007 and Outlook 2007, CDO 1.2.1 will no
longer be provided as a part of the install of the product.

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files
updated see http://www.autofeupdater.com/

Reply With Quote
  #3  
Old   
Douglas J Steele
 
Posts: n/a

Default Re: Email attachment with CDO - 11-07-2011 , 05:15 PM



Not sure whether it's related to your error, but you do not use the New
keyword in conjunction with Set. Try:

Dim objMessage As CDO.Message

Set objMessage = CreateObject("CDO.Message")



"Lou O" wrote in message
news:f3919cc9-5317-4703-b6cd-a6af6def7666 (AT) w20g2000prc (DOT) googlegroups.com...

I have been looking for a way to send an email from access with an
independent file attachment. In other words without using the
sendobject method which sends only access objects.
In this news group I came across the CDO Library method with very
simple code as below

Dim objMessage As New CDO.Message
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.From = "me (AT) my (DOT) com"
objMessage.To = "loosterhoff (AT) gmail (DOT) com"
objMessage.TextBody = "This is some sample message text."
objMessage.AddAttachment "c:\temp\readme.txt"
objMessage.Send

However the code generates the following error running the
Set......CreateObject line

Run-time error '-2147024770(8007007e)':
Automation Error
The specified module could not be found.

Does anyone know what this error means?
Am I missing a class module that this method requires?
I have a suspicion that it refers to MS Outlook (not installed) but
I'm not sure.

Thanks for your help
Lou O

Reply With Quote
  #4  
Old   
Phil
 
Posts: n/a

Default Re: Email attachment with CDO - 11-08-2011 , 03:51 AM



On 07/11/2011 18:02:52, Lou O wrote:
Quote:
I have been looking for a way to send an email from access with an
independent file attachment. In other words without using the
sendobject method which sends only access objects.
In this news group I came across the CDO Library method with very
simple code as below

Dim objMessage As New CDO.Message
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.From = "me (AT) my (DOT) com"
objMessage.To = "loosterhoff (AT) gmail (DOT) com"
objMessage.TextBody = "This is some sample message text."
objMessage.AddAttachment "c:\temp\readme.txt"
objMessage.Send

However the code generates the following error running the
Set......CreateObject line

Run-time error '-2147024770(8007007e)':
Automation Error
The specified module could not be found.

Does anyone know what this error means?
Am I missing a class module that this method requires?
I have a suspicion that it refers to MS Outlook (not installed) but
I'm not sure.

Thanks for your help
Lou O

An alternative is using the Outlook library (I appreciate that you may not
want to use this)

Guts of code is

Function SendEMailAndFiles(MailTo As String, Subject As String, BodyText As
String, IsRtf As Boolean, _ MsgRead As Boolean, Attach() As String, RTFText
As String) As Integer ' MailTo = EMail Address (Bcc)
' Subject = Message subject
' Body is either plain text or Rtf (see IsRtf)
' MsgRead is for reply
' Attach() are any attached files
' Frm is the form driving this procedure

Dim FlgQuit As Boolean
Dim OLApp As Outlook.Application
Dim OLItem As Outlook.MailItem
Dim OLAttachment As Outlook.Attachment
Dim i As Integer, j As Integer, k As Integer, l As Integer
Dim MinSize As Long
Dim AttachmentsFound As Boolean
Dim Contact As String

On Error GoTo Err_SendEMailAndFiles

SysCmd acSysCmdSetStatus, "Sending Email"
CheckAttach:
' Open the source files
For j = LBound(Attach()) To UBound(Attach()) ' No of attachments
If Not IsMissing(Attach(j)) Then 'First attachment
If Attach(j) > "" Then
If Dir(Attach(j)) = "" Then
Call Call apWait(0.5, True) ' Wait 1/2 second
i = i + 1
If i < 3 Then GoTo CheckAttach
If If MsgBox(Attach(j) & " Attachment file not found", vbCritical +
vbRetryCancel) = vbCancel Then Exit Function
Else
GoTo CheckAttach
End If
End If
AttachmentsFound = True ' Valid attachment
End If
End If
If Attach(j) > "" Then
Call Call apWait(0.1, True) ' Wait 1 tenth second
If GetFileSize(CStr(Attach(j)), MinSize) < MinSize Then
GoTo CheckAttach
End If
End If
Next j

SendIt:
SendEMailAndFiles = 0 ' Default situation

'Get Outlook if it's running
On Error Resume Next
Set OLApp = GetObject(, "Outlook.Application")
If Err.Number = 0 Then
FlgQuit = False
Else
Set OLApp = CreateObject("Outlook.Application")
Call apWait(1.5, False)
If OLApp.Session.Offline = True Then
FlgQuit = True
End If
End If
On Error GoTo 0
Err.Clear

On Error GoTo Err_SendEMailAndFiles

If Len(MailTo) > 0 Then
MailTo MailTo = ChangeChars(MailTo, ",", ";") ' Change any commas to
semicolons End If

k k = 1 ' Send email to each person
Do Until k = 0
Contact = Mnu_strDField(MailTo, ";", k) ' Get person's name
If Contact > "" Then
k = k + 1
Else
k = 0
SendEMailAndFiles = 2 ' OK
GoTo CleanUp
End If

'Create a new mailitem and bring Outlook window to front
Set OLItem = OLApp.CreateItem(OLMailItem)
OLItem.Display
FnSetForegroundWindow ("*outlook*")

With OLItem
'Set the recipient for the new email
.To = Contact

'Set the recipient for a copy
.CC = ""
'Set the subject
.Subject = Subject
ReadReceiptRequested iptRequested = MsgRead ' Flag for message read
'The content of the document is used as the body for the email
If IsRtf = True Then ' Rtf message
.BodyFormat = olFormatHTML
.Body = ""
.HTMLBody = RTFText
Else ' Plain text
.HTMLBody = BodyText
End If

'Attachment is the attachment
If AttachmentsFound = True Then
For For j = LBound(Attach()) To UBound(Attach()) ' No of attachments
If Not IsMissing(Attach(j)) Then
If Attach(j) > "" Then
Set OLAttachment = .Attachments.Add(Attach(j))
End If
End If
Next j
End If
Call Call apWait(2, False) ' Time for the email to display before sending
.Send
Set OLItem = Nothing
End With
Loop

DoEvents
SendEMailAndFiles = 2 ' OK

If FlgQuit = True Then
OLApp.Application.Quit
End If

CleanUp:
Set OLItem = Nothing
Set OLApp = Nothing
SysCmd acSysCmdClearStatus
Exit Function

Err_SendEMailAndFiles:
If Err = 287 Then ' No to send email
MsgBox "Email not sent", vbInformation
SendEMailAndFiles = 1
ElseIf Err = 9 Then
AttachmentsFound = False
Resume SendIt
ElseIf seIf Err = -2147467259 Then ' Can't find contact or server refused
connection SendEMailAndFiles = 3
Else
MsgBox Err.Description
End If
GoTo CleanUp

End Function

Reply With Quote
  #5  
Old   
Lou O
 
Posts: n/a

Default Re: Email attachment with CDO - 11-08-2011 , 08:49 AM



Douglas, I removed the "New" keyword but the error persists.
Regarding the missing module referred in the error - do you know what
that is?
Is it a library or something else?
I have downloaded and installed MS Collaboration Data Objects 1.2.1 as
well as Microsoft Exchange Server MAPI Client.
both CDO.dll & CDOsys.dll appear in my System32 folder.
I have checked off CDO Library 1.21 and CDO for Windows 2000 Library
in the references.
The code compiles without errors - but the error still pops up on the
Set .....CreateObject
I must be overlooking or missing something else but I'm not sure what.
Do you have any further ideas? Thanks


On Nov 7, 6:15*pm, "Douglas J Steele"
<NOSPAM_djsteele (AT) NOSPAM_gmail (DOT) com> wrote:
Quote:
Not sure whether it's related to your error, but you do not use the New
keyword in conjunction with Set. Try:

Dim objMessage As CDO.Message

* Set objMessage = CreateObject("CDO.Message")

"Lou O" *wrote in message

news:f3919cc9-5317-4703-b6cd-a6af6def7666 (AT) w20g2000prc (DOT) googlegroups.com...

I have been looking for a way to send an email from access with an
independent file attachment. In other words without using the
sendobject method which sends only access objects.
In this news group I came across the CDO Library method with very
simple code as below

Dim objMessage As New CDO.Message
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.From = "m... (AT) my (DOT) com"
objMessage.To = "loosterh... (AT) gmail (DOT) com"
objMessage.TextBody = "This is some sample message text."
objMessage.AddAttachment "c:\temp\readme.txt"
objMessage.Send

However the code generates the following error running the
Set......CreateObject line

Run-time error '-2147024770(8007007e)':
Automation Error
The specified module could not be found.

Does anyone know what this error means?
Am I missing a class module that this method requires?
I have a suspicion that it refers to MS Outlook (not installed) but
I'm not sure.

Thanks for your help
Lou O

Reply With Quote
  #6  
Old   
Lou O
 
Posts: n/a

Default Re: Email attachment with CDO - 11-08-2011 , 10:13 AM



On Nov 7, 5:25*pm, Tony Toews <tto... (AT) telusplanet (DOT) net> wrote:
Quote:
On Mon, 7 Nov 2011 10:02:49 -0800 (PST), Lou O <lgeastw... (AT) gmail (DOT) com
wrote:

In this news group I came across the CDO Library method with very
simple code as below

Microsoft Access Email FAQ - CDONTShttp://www.granite.ab.ca/access/email/cdonts.htm

Beginning in Exchange Server 2007 and Outlook 2007, CDO 1.2.1 will no
longer be provided as a part of the install of the product.

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages -http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog -http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files
* updated seehttp://www.autofeupdater.com/
Tony are you saying I need to have the above mentioned products
installed in order to run the CDO code successfully?
I have downloaded and installed MS Collaboration Data Objects 1.2.1 as
well as Microsoft Exchange Server MAPI Client,
both CDO.dll & CDOsys.dll appear in my System32 folder.
I have checked off CDO Library 1.21 and CDO for Windows 2000 Library
in the references.
The code compiles without errors - but the error still pops up on the
Set .....CreateObject
What am I still missing?
Thanks

Reply With Quote
  #7  
Old   
Lou O
 
Posts: n/a

Default Re: Email attachment with CDO - 11-08-2011 , 10:19 AM



On Nov 7, 5:25*pm, Tony Toews <tto... (AT) telusplanet (DOT) net> wrote:
Quote:
On Mon, 7 Nov 2011 10:02:49 -0800 (PST), Lou O <lgeastw... (AT) gmail (DOT) com
wrote:

In this news group I came across the CDO Library method with very
simple code as below

Microsoft Access Email FAQ - CDONTShttp://www.granite.ab.ca/access/email/cdonts.htm

Beginning in Exchange Server 2007 and Outlook 2007, CDO 1.2.1 will no
longer be provided as a part of the install of the product.

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages -http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog -http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files
* updated seehttp://www.autofeupdater.com/
Tony are you saying I need to have the above mentioned products
installed in order to run the CDO code successfully?
I have downloaded and installed MS Collaboration Data Objects 1.2.1 as
well as Microsoft Exchange Server MAPI Client.
both CDO.dll & CDOsys.dll appear in my System32 folder.
I have checked off CDO Library 1.21 and CDO for Windows 2000 Library
in the references.
The code compiles without errors - but the error still pops up on the
Set .....CreateObject line of code.
Am I still missing something?
Thank you

Reply With Quote
  #8  
Old   
Tony Toews
 
Posts: n/a

Default Re: Email attachment with CDO - 11-08-2011 , 09:19 PM



On Tue, 8 Nov 2011 08:13:31 -0800 (PST), Lou O
<lgoosterhoff (AT) gmail (DOT) com> wrote:

Quote:
Tony are you saying I need to have the above mentioned products
installed in order to run the CDO code successfully?
No, just that you can't count on CDO being installed.

Quote:
I have downloaded and installed MS Collaboration Data Objects 1.2.1 as
well as Microsoft Exchange Server MAPI Client,
both CDO.dll & CDOsys.dll appear in my System32 folder.
I have checked off CDO Library 1.21 and CDO for Windows 2000 Library
in the references.
The code compiles without errors - but the error still pops up on the
Set .....CreateObject
What am I still missing?
No idea.

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files
updated see http://www.autofeupdater.com/

Reply With Quote
  #9  
Old   
Jon Lewis
 
Posts: n/a

Default Re: Email attachment with CDO - 11-09-2011 , 08:36 AM



I tried this and had no error on the CreateObject line. The only CDO
reference I have is to cdosys.dll. That said I do get an error on the
objMessage.Send line as you have to configure the SMTP server details before
you can send using CDO. The following seems a good tutorial on the subject
in a VB/VBA environment:

http://www.developerfusion.com/artic...mail-dispatch/

HTH

Jon


"Lou O" <lgeastwood (AT) gmail (DOT) com> wrote

Douglas, I removed the "New" keyword but the error persists.
Regarding the missing module referred in the error - do you know what
that is?
Is it a library or something else?
I have downloaded and installed MS Collaboration Data Objects 1.2.1 as
well as Microsoft Exchange Server MAPI Client.
both CDO.dll & CDOsys.dll appear in my System32 folder.
I have checked off CDO Library 1.21 and CDO for Windows 2000 Library
in the references.
The code compiles without errors - but the error still pops up on the
Set .....CreateObject
I must be overlooking or missing something else but I'm not sure what.
Do you have any further ideas? Thanks


On Nov 7, 6:15 pm, "Douglas J Steele"
<NOSPAM_djsteele (AT) NOSPAM_gmail (DOT) com> wrote:
Quote:
Not sure whether it's related to your error, but you do not use the New
keyword in conjunction with Set. Try:

Dim objMessage As CDO.Message

Set objMessage = CreateObject("CDO.Message")

"Lou O" wrote in message

news:f3919cc9-5317-4703-b6cd-a6af6def7666 (AT) w20g2000prc (DOT) googlegroups.com...

I have been looking for a way to send an email from access with an
independent file attachment. In other words without using the
sendobject method which sends only access objects.
In this news group I came across the CDO Library method with very
simple code as below

Dim objMessage As New CDO.Message
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.From = "m... (AT) my (DOT) com"
objMessage.To = "loosterh... (AT) gmail (DOT) com"
objMessage.TextBody = "This is some sample message text."
objMessage.AddAttachment "c:\temp\readme.txt"

However the code generates the following error running the
Set......CreateObject line

Run-time error '-2147024770(8007007e)':
Automation Error
The specified module could not be found.

Does anyone know what this error means?
Am I missing a class module that this method requires?
I have a suspicion that it refers to MS Outlook (not installed) but
I'm not sure.

Thanks for your help
Lou O

Reply With Quote
  #10  
Old   
Lou O
 
Posts: n/a

Default Re: Email attachment with CDO - 11-09-2011 , 11:52 AM



On Nov 8, 10:19*pm, Tony Toews <tto... (AT) telusplanet (DOT) net> wrote:
Quote:
On Tue, 8 Nov 2011 08:13:31 -0800 (PST), Lou O

lgoosterh... (AT) gmail (DOT) com> wrote:
Tony are you saying I need to have the above mentioned products
installed in order to run the CDO code successfully?

No, just that you can't count on CDO being installed.

I have downloaded and installed MS Collaboration Data Objects 1.2.1 as
well as Microsoft Exchange Server MAPI Client,
both CDO.dll & CDOsys.dll appear in my System32 folder.
I have checked off CDO Library 1.21 and CDO for Windows 2000 Library
in the references.
The code compiles without errors - but the error still pops up on the
Set .....CreateObject
What am I still missing?

No idea.

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages -http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog -http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files
* updated seehttp://www.autofeupdater.com/
Hi Tony,
Sorry to belabor this but I'd really like to get this Email attachment
thing working if at all possible.
In your opinion should the procedure work with the 8 lines of code as
I've posted?
In other words is that all there is to the code? It looks a bit too
easy but I'm all for easy.
If that is all there is to it then could you suggest where else I
should start looking for a fix? ei CDO version
Thanks for your help.
Lou

Reply With Quote
Reply




Thread Tools
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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.