PDA

View Full Version : VBA to populate Subject field



redmancstu
01-20-2011, 03:19 AM
Hi

I'm after some vba code that can be run when I click on new message that will fill the subject line with the same text each time, e.g. "shipment notification". The main body of the email is saved as a signature which displays automatically, so that is not a bother.

Any help, muchly appreciated.

Regards
Stuart

gcomyn
01-21-2011, 01:18 PM
that could be done, but then when you wanted to send an email that wasn't for the "shipment notification", you would need to erase what is automatically put there.

I would suggest using an access database to generate your letters... that way, when or if the body of the letter changed, you could easily change it, and it would stay that way until it needed to be changed again. (I know... everyone says this is the final version, but someone always comes up with a changes that needs to be done...)

In the access database, you would have a table that had 2 fields, minimum... one for the subject, and one for the body. You could add more, if you needed.

Then on the form, you would have the To:, the CC: and the BCC: (as needed) that you would fill in, then the Subject and body would also have a text field. Then you would have a button that would send the email.

I've put together an Access database that I've attached. It is in 2002-2003 format (I used 2007 to make it). It has a table and a form only, and there is only code to send an email. I've set it to save the email to your Drafts folder, but to change it to automatically send, just comment out the mItem.Save line and uncomment the mItem.Send line.

Let me know what you think, and if this is what you were looking for.

GComyn
:sleuth:

redmancstu
01-24-2011, 02:00 AM
Dear gcomyn

This is crazy! You have gone way above and beyond the call of duty here. Thanks for taking the time to help little ol me.
Your access jobby works great and is so simple to use.
I have changed the code and sent a few test emails to my self and it works great. The vba code is very well set out, you are obviously a pro at this - it makes it all that little bit easier to understand.

I have one issue though. My knowledge of access is limited and vba even more so. If I was to make an extra field in tblEMail called attachments and then put the field in the frmEmail as well, is it as easy as that to be able to add and send an attachment?

I'm very grateful for your help so far. Thanks again
Stu

gcomyn
01-24-2011, 07:56 AM
yes.. it was easy, especially as I already had the mailing functions already written (since I use them all the time), so just getting the table and form were easy... I've added Attachment availability for you.

You have to put the entire path of the file you want. I've coded it to look in the 'C:\Attachments\' folder, so if you put a file in there, and open the form, it will put that file name (with path) in the attachment text box. It also has functionality for multiple files.

Like I said.. this is just a quick and dirty form... just what you asked for at first... You could also add a table of email addresses, then another form with them listed in a continuous form, and have a checkbox next to those that you want to send the email to... then have the code go through the recordset of the form, and email each one the same thing.....

If that is something you think you could use, try it for yourself, and let me see what you get.

Also... what changes did you make to the code? I'm curious to see if I should make those changes as well.

GComyn
:sleuth: