Full Version: AC 2003 Send Emai Type Mismatch
UtterAccess Discussion Forums > Microsoft® Access > Access Automation
geohawk
I'm using Access 2003 with Outlook 2003 to send email using the code provided below. When I compile the code everything is fine but soon as I run it, I get a run-time error 13, Type mismatch, message on the line with the *asterik next to it. (The asterik is not included in the code when I run it). I got this code from the microsoft knowledge base. What's the problem?

Public Sub SendMessages(Optional AttachmentPath)

Dim MyDB As Database
Dim MyRS As Recordset
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim TheAddress As String
Dim TheSubject As String
Dim TheMainText As String
Dim TheMainText1 As String
Dim TheMainText2 As String
Dim ID As String
Dim CCAddress As String

Set MyDB = CurrentDb
*Set MyRS = MyDB.OpenRecordset("tblMailingList")

MyRS.MoveFirst

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

Do Until MyRS.EOF

' Create the e-mail message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
TheAddress = MyRS![EMAILADDRESS]

With objOutlookMsg
' Add the To recipient(s) to the e-mail message.
Set objOutlookRecip = .Recipients.Add(TheAddress)
objOutlookRecip.Type = olTo

' Add the CC recipient(s) to the e-mail message.
If (IsNull(Forms!frmMail!CCAddress)) Then
Else
Set objOutlookRecip = .Recipients.Add(Forms!frmMail!CCAddress)
objOutlookRecip.Type = olCC
End If

' Set the Subject, Body, and Importance of the e-mail message.
.SUBJECT = Forms!frmMail!SUBJECT
.Body = (TheMainText) & vbCrLf & vbCrLf & (TheMainText1) & vbCrLf & vbCrLf & (TheMainText2)
.Importance = olImportanceHigh 'High importance

'Add attachments to the e-mail message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If

' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send
End With
MyRS.MoveNext
Loop
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
freakazeud
Hi,
This is most likely a referencing issue...have you checked this article?
HTH
Good luck
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.