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:
The issue I'm having is the
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
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
Thanks