Email with Attachments

User avatar
HansV
Administrator
Posts: 78445
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Email with Attachments

Post by HansV »

Thanks. What does the EmailAttachments field contain?
Best wishes,
Hans

Leesha
BronzeLounger
Posts: 1487
Joined: 05 Feb 2010, 22:25

Re: Email with Attachments

Post by Leesha »

Names of the attachements. The user selects the attachment they want to add to the email

User avatar
HansV
Administrator
Posts: 78445
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Email with Attachments

Post by HansV »

Could you attach a sample database again?
Best wishes,
Hans

Leesha
BronzeLounger
Posts: 1487
Joined: 05 Feb 2010, 22:25

Re: Email with Attachments

Post by Leesha »

Absolutely!
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78445
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Email with Attachments

Post by HansV »

How about this?

Hans.zip
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

Leesha
BronzeLounger
Posts: 1487
Joined: 05 Feb 2010, 22:25

Re: Email with Attachments

Post by Leesha »

It works!!!! It gave me an error at first that said that the database was locked by another user. I closed it an reopened and it didn't give me the error again. Now I need to pull into the main DB. Pray it doesn't give me any grief so I can leave you alone! Thanks so much! I can't wait to study the code.
Leesha

Leesha
BronzeLounger
Posts: 1487
Joined: 05 Feb 2010, 22:25

Re: Email with Attachments

Post by Leesha »

It ran form the main database!!! :fanfare: Thank you so very much!
Leesha

User avatar
HansV
Administrator
Posts: 78445
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Email with Attachments

Post by HansV »

Keep in mind that you or the end user will have to edit the EmailAttachments field, since it now uses your PC's path.
Best wishes,
Hans

Leesha
BronzeLounger
Posts: 1487
Joined: 05 Feb 2010, 22:25

Re: Email with Attachments

Post by Leesha »

Gotcha! Thanks again!

Leesha
BronzeLounger
Posts: 1487
Joined: 05 Feb 2010, 22:25

Re: Email with Attachments

Post by Leesha »

Hi Hans,
I've managed to add some formatting to what you built for me and have not blown it up! I am wondering if it is possible to format me.FirstName in the code below? If it's possible I'd like it to be Segoe Script in a 16 bold.
Thanks for everything!
Leesha

.Body = Me.Comment & vbCrLf & vbCrLf & vbCrLf & vbCrLf & Me.ClosingStatement & vbCrLf & vbCrLf & Me.FirstName

User avatar
HansV
Administrator
Posts: 78445
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Email with Attachments

Post by HansV »

The .Body property is plain text.
If you want formatted text you can either use the .HTMLBody property or use Word to format the text.
The HTMLBody property requires HTML markup code:

.HTMLBody = "<body><font face=""Segoe Script"" size=""16pt""><b>" & Me.Comment & "<br><br><br><br>" & Me.ClosingStatement & "<br><br>" & Me.FirstName & "</b></font></body>"
Best wishes,
Hans

Leesha
BronzeLounger
Posts: 1487
Joined: 05 Feb 2010, 22:25

Re: Email with Attachments

Post by Leesha »

Hi Hans!
Thanks so much for the sample code. If I wanted only me.firstname to be in the Segoe Sript and the rest of the .Body to be in plain text is that possible and if so what would it look like?
Thanks!

User avatar
HansV
Administrator
Posts: 78445
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Email with Attachments

Post by HansV »

Try


.HTMLBody = "<body>" & Me.Comment & "<br><br><br><br>" & Me.ClosingStatement & "<br><br><font face=""Segoe Script"" size=""16pt""><b>" & Me.FirstName & "</b></font></body>"
Best wishes,
Hans

Leesha
BronzeLounger
Posts: 1487
Joined: 05 Feb 2010, 22:25

Re: Email with Attachments

Post by Leesha »

Hi Hans,
It does the same thing as the original one. It's OK. I am thrilled with what the original code. The user asked if there was any way to change the font for the first name but I'm sure they will live with it the way it is.
Thanks!
Leesha

Leesha
BronzeLounger
Posts: 1487
Joined: 05 Feb 2010, 22:25

Re: Email with Attachments

Post by Leesha »

Not to worry Hans, this is all working beautifully! My question is ............. is there a way to specify which email address it is coming from. One of the end users has a variety of email addresses based on the job she is performing. Right now the email goes out from her default email address. He wants to know if there is a way to pick a different email address within Access vs having to go to Outlook and change the default each time.
Thanks,
Leesha

User avatar
StuartR
Administrator
Posts: 12604
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Email with Attachments

Post by StuartR »

Try adding
.SendUsingAccount = "account name"
To the code that creates the email
(replace account name with the full name of the account you want to use)
StuartR


Leesha
BronzeLounger
Posts: 1487
Joined: 05 Feb 2010, 22:25

Re: Email with Attachments

Post by Leesha »

Hi Stuart,
I tried the code but it still shows as coming from my default email in Outlook. I wasn't sure where to insert the code so put it after . body. Should it be elsewhere?
Thanks,
Leesha

User avatar
HansV
Administrator
Posts: 78445
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Email with Attachments

Post by HansV »

It should be before the line that displays or sends the message. Below the line that sets the body is fine. Try this:

Code: Select all

            .SendUsingAccount = outApp.GetNameSpace("MAPI").Accounts("email address")
substituting the desired email address.
Best wishes,
Hans

Leesha
BronzeLounger
Posts: 1487
Joined: 05 Feb 2010, 22:25

Re: Email with Attachments

Post by Leesha »

I get an error that says wrong number of arguments or invalid property assignment.

User avatar
HansV
Administrator
Posts: 78445
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Email with Attachments

Post by HansV »

Start Outlook and activate the Visual Basic Editor.
Select Insert > Module, then copy/paste the following code:

Code: Select all

Sub List()
    Dim a As Account
    For Each a In Session.Accounts
        Debug.Print a.UserName
    Next a
End Sub
You should see the names of all your email accounts in the Ommediate window. Did you use one of those?

(You don't need to save changes to the VBA project in Outlook.
Best wishes,
Hans