Is there any way to send an email with an attachment from within my code. I don't want to send an access object. I want to send a file that is saved on my system. is this possible?
Thank you
Is there any way to send an email with an attachment from within my code. I don't want to send an access object. I want to send a file that is saved on my system. is this possible?
Thank you
Sure, are you wanting to send it through MS Outlook or another program?
"Computers are useless. They can only give you answers." - Pablo Picasso
Mark Rowlinson FIA | The Code Net
I've assumed I'd have to send it with Outlook so that would be fine.
I've assumed I'd have to send it with Outlook so that would be fine.
I've never tried automating outlook, but if you're talking about an attachment that's an office doc, then you can probably use send mail from that app and control it from Access. Alternatively, you might find this helpful...http://support.microsoft.com/default...b;en-us;161088
To automate Outlook you can use the following:
[vba]
Sub SendMail()
Dim olApp As Outlook.Application
Dim olMail As Outlook.MailItem
'get application
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If olApp Is Nothing Then Set olApp = New Outlook.Application
On Error GoTo 0
Set olMail = olApp.CreateItem(olMailItem)
With olMail
.Subject = "My email with attachment"
.Recipients.Add "name@host.com"
.Attachments.Add "c:\test.txt"
.Body = "Here is an email"
.Display 'This will display the message for you to check and send yourself
'.Send ' This will send the message straight away
End With
End Sub
[/vba]
Note that for versiosn of Outlook above 2000 you will get security warnings that a program is trying to control it which can make it awkward to use.
"Computers are useless. They can only give you answers." - Pablo Picasso
Mark Rowlinson FIA | The Code Net
Mark, if that's not already a KB entry, you should submit it.