PDA

View Full Version : email an attached file using MS Access



DBinPhilly
07-31-2018, 06:15 AM
A customer needs to email various attachments that have not been created in MS Access. He wants to use his Access system which includes his entire customer base with email addresses to do the mailing.

So far I've done the following legwork: created a form with a built in MS Explorer function so he can easily select the file he wishes to send, along with a place for him to key some text and the ability to easily select the customer/customers to receive the email.

That's about as far as I've gotten. I tried putting a command button on my form to use the DoCmd.SendObject statement, but that is obviously a mistake. No where that I can tell to put the object path for the attachment.

I've rarely used email in an Access system, so it's quite possible I'm just ignorant.

Any ideas?

OBP
08-01-2018, 08:15 AM
Hi, the docmd object is not very good at sending attachments.
Here is the code that I used, it should have Error Trapping added,


Dim objOutlook As New Outlook.Application ' outlook object
Dim objMessage As MailItem, strAttach As String ' outlook mail message
Dim Subject As String, Body As String, EmailAddress As String
EmailAddress = Me.EmailAddress
strAttach = Me.Attachment
Set objMessage = objOutlook.CreateItem(olMailItem)
With objMessage
.To = EmailAddress
.Subject = "Test Send"
.Body = "This is a Test"
.Attachments.Add strAttach
.DisplayName = "Joe Bloggs"
.Send
End With
Set objOutlook = Nothing
Set objMessage = Nothing

DBinPhilly
08-01-2018, 11:16 AM
Hi, the docmd object is not very good at sending attachments.
Here is the code that I used, it should have Error Trapping added,


Dim objOutlook As New Outlook.Application ' outlook object
Dim objMessage As MailItem, strAttach As String ' outlook mail message
Dim Subject As String, Body As String, EmailAddress As String
EmailAddress = Me.EmailAddress
strAttach = Me.Attachment
Set objMessage = objOutlook.CreateItem(olMailItem)
With objMessage
.To = EmailAddress
.Subject = "Test Send"
.Body = "This is a Test"
.Attachments.Add strAttach
.DisplayName = "Joe Bloggs"
.Send
End With
Set objOutlook = Nothing
Set objMessage = Nothing

I've tried adding your code but it bumps up against a
User_Defined type not defined
error. Am I missing a reference library? Do I need to declare the Outlook.Application elsewhere?
I am using Access 365.

OBP
08-01-2018, 11:34 AM
Yes you will definitely need to set the Library References to Outlook.

DBinPhilly
08-01-2018, 03:40 PM
Yes you will definitely need to set the Library References to Outlook.

.did that up front, still got the error message listed above.

OBP
08-02-2018, 12:32 AM
Have you got an Equivelent of Me.EmailAddress?
That comes from the Form that I use to test various types of emailing.
Here is the database.