Adding Attachments to Outlook - Runtime Error '13' Type Mismatch (1 Viewer)

Squizzla

New member
Local time
Today, 06:06
Joined
Jan 13, 2014
Messages
5
Hello everyone,

I'm having a bit of bother with a Access VBA function that attaches files to an email and sends them to a specified list of addresses.

Here is the function:

Code:
Function SendEmail() As Boolean
 
Dim olApp As Outlook.Application
Dim olMailItemObject As Outlook.MailItem
Dim objfile As Scripting.File
Dim fso As New Scripting.FileSystemObject
Dim bSucc As Boolean
Dim hResult As Boolean
 
On Error GoTo email_Err
 
'Create objects
   Set olApp = CreateObject("Outlook.application")
   Set olMailItemObject = olApp.CreateItemFromTemplate(Forms!frmMailer.lblTempPath.Caption)
 
 
  For Each objfile In fso.GetFolder(CurrentProject.Path & "\Temp Files").Files
      'Add attachment
      olMailItemObject.Attachments.Add objfile.Path, objfile.Type
      NoFiles = NoFiles + 1
  Next
 
  If NoFiles = 0 Then
      ErrString = "No Attachments"
      GoTo email_Err
  End If
 
'Add recipient
   hResult = AddRecipients(olMailItemObject, Forms!frmMailer.lblEmail.Caption)
 
'Send email
  olMailItemObject.Recipients.ResolveAll
  olMailItemObject.Send
 
'Success
  SendEmail = True
  bSucc = True
 
email_Err:
  'Release pointers
    Set olMailItemObject = Nothing
    Set olApp = Nothing
    Set fso = Nothing
  If bSucc = False And ErrString = "" Then ErrString = "Could not email  Recipients"
 
End Function

The issue I'm having is the
Code:
olMailItemObject.Attachments.Add objfile.Path, objfile.Type
line, which it fails on giving me run-time error '13' - Type mis-match. A little liberal googling has failed to help, so I was hoping someone here would have an idea of what's going wrong & how to fix it.

Thanks
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 22:06
Joined
Aug 30, 2003
Messages
36,125
Shot in the dark but try dropping the last bit:

olMailItemObject.Attachments.Add objfile.Path
 

Squizzla

New member
Local time
Today, 06:06
Joined
Jan 13, 2014
Messages
5
Excellent in-the-dark shooting - it sorted it perfectly. Thanks!

Any idea why that might have been the case?
 

Users who are viewing this thread

Top Bottom