Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Emails to Multiple Addresses 2

Status
Not open for further replies.

rosieb

IS-IT--Management
Sep 12, 2002
4,279
GB
I have a form with a continuous sub-form containing contacts, including their email addresses.

I want to set up a button on the main form which opens an email (Outlook) with all of the email addresses in the To: field.

I can work out how to send an email to a single address, but I'm stuck on the multiples.

Can anyone point me in the right direction?

Rosie
"Never express yourself more clearly than you think" (Niels Bohr)
 
Check out the Docmd.SendObjects command. This can be used to send emails.

Code:
DoCmd.SendObject [objecttype][, objectname][, outputformat][, to][, cc][, bcc][, subject][, messagetext][, editmessage][, templatefile]

As you can see there are parameters here for the To, CC, and BCC entries in an email. You can use a recordset to loop through a series of records and cancatenate the email addresses together seperated by a semi-colon. Then use that string as the To parameter.

Post back if you need more assistance.

Bob Scriver
[blue]Want the best answers? See FAQ181-2886[/blue]


 
Bob

Thanks, recordset is rather pushing my level of competence, so it will probably take me a while, but now I know where to start.

Rosie
"Never express yourself more clearly than you think" (Niels Bohr)
 
Just a hint. If the list is very static and unchanging you can just set a variable in VBA code and assign the email string to the variable. Then use the variable as the TO parameter in the command. Or just enter the email string within quotes as the parameter itself.

Secondly, if the email list is a changing one and has to be selected from a table then the Recordset option where you loop through and build the string is necessary.

If you need specific help with code please post back and I will help you.

Bob Scriver
[blue]Want the best answers? See FAQ181-2886[/blue]


 
Bob

It looks as though I need the recordset. I'll play with it over the break, I really ought to be able to do this, and I'd sooner work it out myself.

I'll ask for help if I get really stuck - your kind offer is much appreciated.

Rosie
"Never express yourself more clearly than you think" (Niels Bohr)
 
Bob

Thanks to your hints I got this up and working, so thanks.

But I have hit an irritating problem. If I cancel the email without sending I get Error 2501 The SendObject Action was cancelled.

I've tried using DoCmd.SetWarnings False but that doesn't seem to work, any suggestions?




Rosie
"Never express yourself more clearly than you think" (Niels Bohr)
 
Hi!

I use the error handling routine.

- at the top of the routine something like this:

[tt]on error goto MyErr[/tt]

- at the bottom of the routine

[tt]MyExit:
exit sub
MyErr:
if err.number<>2501 then
msgbox err.description
end if
resume MyExit
end sub[/tt]

Roy-Vidar
 
Hi

In the event where you have the sendobject trap the error, at its most basic:

OnError GoTo ErrorTrap

ErrorTrap:
if err.number = 2501 then
resume next
else
msgbox err.description
end if

or even just on error resumenext

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Roy, Ken

Thanks both!

Rosie
"Never express yourself more clearly than you think" (Niels Bohr)
 
Remember that under XP (and 2003) there is a new security protocol that makes using SendObject a little difficult.

If XP is the target platform, you may need to research some options:

htwh,

Steve Medvid
&quot;IT Consultant & Web Master&quot;

Chester County, PA Residents
Please Show Your Support...
 
smedvid: Have a star on me as this is very helpful information and one that I was not aware of. Will surely incorporate this in future postings.

Bob Scriver
[blue]Want the best answers? See FAQ181-2886[/blue]


 
Steve

I think that may explain why I just spotted a problem on my XP test machine (I'd assumed it was just because the machine ia a bit temperamental, needs a reload!). Very useful-looking links.

Thanks very much for that, even by this forum's standards very inpressive - solving my problem before I realised, I had one! Any suggestions for tomorrow? [smile]

Rosie
"Never express yourself more clearly than you think" (Niels Bohr)
 
Suggestion for Tomorrow:

Always expect the unexpected, but have confidence that it can be solved with ACCESS

Spoken like a true ACCESS developer.

Bob Scriver
[blue]Want the best answers? See FAQ181-2886[/blue]


 
Bob

Thanks for the suggestion. I was hoping more for a "Your problem with abc can be solved by xyz" - psychic problem solving.

Thanks again to all, and a belated star for smedvid (I can't do stars from work).

Rosie
"Never express yourself more clearly than you think" (Niels Bohr)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top