Problem adding attachments to Outlook Mailitem

tschwend

New member
Local time
Today, 05:15
Joined
Apr 15, 2013
Messages
1
I have a simple task that I am not able to get working. I am creating an Outlook Mailitem to display, but when I try to add attachments to it, I get a runtime error 438 - Object doesn't support this property or method.

The error is occurring when I try to use the mailitem's Attachments.Add method. It looks to me to be a reference problem. I have a reference to the Outlook.12.0 library.

Another interesting this is when I type the code in, it shows the Add method in the list of methods. That tells me it's in the definition of the Attachments class. After selecting the Add method from the list, finish the line and press enter, the Add method changes to all lowercase, like it doesn't recognize it. I've tried typing in the other methods of the Attachments class and those methods stay uppercase.

I've also tried late binding, but the same things happens.

Below is my code, any ideas?

Thanks, Tom

Private Sub SendEmailFromMemo()

Dim otlkApp As Outlook.Application
Dim otlkItem As Outlook.MailItem
Dim db As ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strSQL As String
Dim emailstr As String


' validate all info is filled out
If Me.MemoSubject = "" Then
MsgBox "Enter a Subject First.", , "Cannot Send Email"
Exit Sub
ElseIf Me.MemoText = "" Then
MsgBox "Enter Message First.", , "Cannot Send Email"
Exit Sub
ElseIf Me.MemoClient = 0 Then
MsgBox "Select a Contact First.", , "Cannot Send Email"
Exit Sub
End If

' get the email address of the contact to send to
Set db = CurrentProject.Connection
Set rst.ActiveConnection = db
strSQL = "SELECT Email FROM Client where Client = " & _
Me.MemoClient
rst.Open strSQL, db, adOpenKeyset, adLockOptimistic

If rst.Fields("Email") = "" Then
MsgBox "Contact Has No Email Address.", , "Cannot Send Email"
rst.Close
Set rst = Nothing
Set db = Nothing
Exit Sub
Else
emailstr = rst.Fields("Email")
End If

rst.Close

' Open a connection to outlook and create mailitem
Set otlkApp = CreateObject("Outlook.Application")
Set otlkItem = otlkApp.CreateItem(olMailItem)

' enter info
otlkItem.To = emailstr
otlkItem.Subject = Me.MemoSubject
otlkItem.Body = Me.MemoText
otlkItem.Save

' see if there are any attachments to send
strSQL = "SELECT * FROM MemoAttachments WHERE MemoID = " & _
Me.MemoID
rst.Open strSQL, db, adOpenKeyset, adLockOptimistic

If rst.RecordCount > 0 Then

Do Until rst.EOF
If FileExit(rst!FileName) Then
otlkItem.Attachments.add rst!FileName
End If
rst.MoveNext
Loop
End If

' display the email
otlkItem.Display

' clean up and exit
Set rst = Nothing
Set db = Nothing
Set otlkItem = Nothing
Set otlkApp = Nothing

End Sub
 

Users who are viewing this thread

Back
Top Bottom