Sending CDO E-mail

M

MDW

Based on a question I had in an Outlook forum, I decided to move to CDO to
send e-mails via Access. However, I'm getting a "type mismatch" error in the
code that I pulled from the MSDN Library. I'm using Access 2003. Below is the
relevant code (error indicated inline).

If it matters, this code is being executed on a standard workstation and not
a server.

Dim objMsg As CDO.Message

Dim objConfig As CDO.Configuration
Dim objField As ADODB.Field
Dim objFields As ADODB.Fields

Set objMsg = New CDO.Message

objMsg.Subject = strSubject
objMsg.TextBody = strMessage
objMsg.From = "(e-mail address removed)"
objMsg.To = objAdmin(1).Value

' Set configuration.
Set objConfig = New CDO.Configuration
Set objFields = objConfig.Fields << TYPE MISMATCH

objField =
objFields("http://schemas.microsoft.com/cdo/configuration/sendusing")
objField.Value = 1 ' Sets the configuration to use the local SMTP server
objFields.Refresh

objMsg.Configuration = objConfig

objMsg.Send

Set objMsg = Nothing
 
D

David Lloyd

When I reference the ADO 2.1 Library to run your code, I get a type mismatch
error on the line you indicated. When I change this reference to the ADO
2.5 Library, the error no longer is generated.

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


Based on a question I had in an Outlook forum, I decided to move to CDO to
send e-mails via Access. However, I'm getting a "type mismatch" error in the
code that I pulled from the MSDN Library. I'm using Access 2003. Below is
the
relevant code (error indicated inline).

If it matters, this code is being executed on a standard workstation and not
a server.

Dim objMsg As CDO.Message

Dim objConfig As CDO.Configuration
Dim objField As ADODB.Field
Dim objFields As ADODB.Fields

Set objMsg = New CDO.Message

objMsg.Subject = strSubject
objMsg.TextBody = strMessage
objMsg.From = "(e-mail address removed)"
objMsg.To = objAdmin(1).Value

' Set configuration.
Set objConfig = New CDO.Configuration
Set objFields = objConfig.Fields << TYPE MISMATCH

objField =
objFields("http://schemas.microsoft.com/cdo/configuration/sendusing")
objField.Value = 1 ' Sets the configuration to use the local SMTP server
objFields.Refresh

objMsg.Configuration = objConfig

objMsg.Send

Set objMsg = Nothing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top