Connecting Tech Pros Worldwide Help | Site Map

How to send email via code in an Access Project?

Tim Smallwood
Guest
 
Posts: n/a
#1: Nov 12 '05

Hi,

I have an Access project that I use to allow a client to hit an SQL
server at my host. This project has several forms that are used to
udpate tables, etc, but I'd also like to be able to include the ability
to allow my client to send an email to everyone that has subscribed to
our web site by going to the table that contains the names and email
addy's and then loop thru the same and send an email to them all by
appending their address to the email TO: field.. or BCC< etc.. I've done
this in ASP, and VB, but not in access.. I of course will be using the
SMTP server at my hosting provider for this.. Can someone point me to
some sample code to do this? I'm using Access 2002 / Office pro 2002..
Thanks



Tim

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Tony Toews
Guest
 
Posts: n/a
#2: Nov 12 '05

re: How to send email via code in an Access Project?


Tim Smallwood <dotnettim@netscape.net> wrote:
[color=blue]
>I have an Access project that I use to allow a client to hit an SQL
>server at my host. This project has several forms that are used to
>udpate tables, etc, but I'd also like to be able to include the ability
>to allow my client to send an email to everyone that has subscribed to
>our web site by going to the table that contains the names and email
>addy's and then loop thru the same and send an email to them all by
>appending their address to the email TO: field.. or BCC< etc.. I've done
>this in ASP, and VB, but not in access.. I of course will be using the
>SMTP server at my hosting provider for this.. Can someone point me to
>some sample code to do this? I'm using Access 2002 / Office pro 2002..[/color]

See the Sample Code illustrating looping through a DAO recordset page at the Access
Email FAQ at http://www.granite.ab.ca/access/email/recordsetloop.htm

Tony

--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
John Winterbottom
Guest
 
Posts: n/a
#3: Nov 12 '05

re: How to send email via code in an Access Project?


"Tim Smallwood" <dotnettim@netscape.net> wrote in message
news:40aac5e3$0$207$75868355@news.frii.net...[color=blue]
>
> Hi,
>
> I have an Access project that I use to allow a client to hit an SQL
> server at my host. This project has several forms that are used to
> udpate tables, etc, but I'd also like to be able to include the ability
> to allow my client to send an email to everyone that has subscribed to
> our web site by going to the table that contains the names and email
> addy's and then loop thru the same and send an email to them all by
> appending their address to the email TO: field.. or BCC< etc.. I've done
> this in ASP, and VB, but not in access.. I of course will be using the
> SMTP server at my hosting provider for this.. Can someone point me to
> some sample code to do this? I'm using Access 2002 / Office pro 2002..
> Thanks
>
>[/color]


http://www.aspfaq.com/show.asp?id=2403


Tim Smallwood
Guest
 
Posts: n/a
#4: Nov 12 '05

re: How to send email via code in an Access Project?


Tony,

Thanks so much.. I'm at the site now, and what a great web site.. Love
the UI design stuff..


Tim

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Tony Toews
Guest
 
Posts: n/a
#5: Nov 13 '05

re: How to send email via code in an Access Project?


Tim Smallwood <dotnettim@netscape.net> wrote:
[color=blue]
>Thanks so much.. I'm at the site now, and what a great web site.. Love
>the UI design stuff..[/color]

Thanks for the comments. They make the effort worthwhile.

But, umm, what UI design stuff? Other than the one dealing with combing families for
reducing mailing costs I don't have much UI stuff.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Lauren Quantrell
Guest
 
Posts: n/a
#6: Nov 13 '05

re: How to send email via code in an Access Project?


Tim,
This is how I have done it.
Create a stored procedure named "GetEMailAddresses"
Create a function to loop through the stored procedure.
Code is below. I hope this helps.
lq


The stored procedure:

/* Create list of e-mail addresses from tblEmployees */

Alter Procedure GetEMailAddresses
As
SELECT
EmailAddress
FROM
tblEmployees
WHERE
(InactiveEmployee = 0)
AND
(EmailAddress Is Not Null)
ORDER BY
tblEmployees.WorkCity

The Function:

Function EmailList()
On Error GoTo myErr
'PURPOSE: Returns a string list of all employees with an e-mail
addresses that are still active employees

Dim RS As ADODB.Recordset, myAddress As String, mySP As
String, _
myField As String, mySubject as string, myMsg as string

mySP = "GetEMailAddresses"
myField = "EmailAddress"
Set RS = CurrentProject.Connection.Execute("EXEC " & mySP)
myAddress = ""
If Not RS.BOF And Not RS.EOF Then '>has found at least one
record:
Do While Not RS.EOF
myAddress = myAddress & ";" & RS(myField)
RS.MoveNext
Loop
End If
myAddress = Mid(myAddress, 2)

'call your email program using sendobject or another function:

mySubject = "Notice to all employees"
myMsg = "If you are receiving this email it means your job has
been eliminated and you should consider yourself immediately
terminated." & vbcrlf & "Your job has been outsourced to a cheaper
country."

DoCmd.SendObject acSendNoObject, , , myAddress, , ,
mySubject, myMsg, True

myExit:
On Error Resume Next
RS.Close
Set RS = Nothing
Exit Function
myErr:
If Err.Number = 2296 Or Err.Number = 2501 Then
'user cancelled the email after the email template opened
ElseIf Err.Number = 3021 Then
MsgBox "There are no records that match your search.",
vbInformation, "Search Results"
ElseIf Err.Number = 94 Then 'there was a record but it contains a
null value:
'>user cancelled
Else
MsgBox Err.Number & " " & Err.Description
End If
Resume myExit
End Function




Tim Smallwood <dotnettim@netscape.net> wrote in message news:<40aac5e3$0$207$75868355@news.frii.net>...[color=blue]
> Hi,
>
> I have an Access project that I use to allow a client to hit an SQL
> server at my host. This project has several forms that are used to
> udpate tables, etc, but I'd also like to be able to include the ability
> to allow my client to send an email to everyone that has subscribed to
> our web site by going to the table that contains the names and email
> addy's and then loop thru the same and send an email to them all by
> appending their address to the email TO: field.. or BCC< etc.. I've done
> this in ASP, and VB, but not in access.. I of course will be using the
> SMTP server at my hosting provider for this.. Can someone point me to
> some sample code to do this? I'm using Access 2002 / Office pro 2002..
> Thanks
>
>
>
> Tim
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it![/color]
John Winterbottom
Guest
 
Posts: n/a
#7: Nov 13 '05

re: How to send email via code in an Access Project?


"Lauren Quantrell" <laurenquantrell@hotmail.com> wrote in message
news:47e5bd72.0405220659.53eee85e@posting.google.c om...[color=blue]
> Tim,
> This is how I have done it.
> Create a stored procedure named "GetEMailAddresses"
> Create a function to loop through the stored procedure.
> Code is below. I hope this helps.
> lq
>
>[/color]

If you're using sql server and you have permissions to do so I recommend
configuring mail on the server instead of the client. You only have to
configure it once and thereafter it will work for everyone - even if you
decide to move to a new front-end. You don't need to worry about references,
libraries, outlook versions etc. etc. It's a lot easier to set up and to
administer.


Lauren Quantrell
Guest
 
Posts: n/a
#8: Nov 13 '05

re: How to send email via code in an Access Project?


John,
Is there a nutshell version of how this is done? I've never tried
doing this. How does the server resolve issues involving the sender
and return address for a sender's e-mail if everyone is hitting the
same server-side mail client?
lq

"John Winterbottom" <assaynet@hotmail.com> wrote in message news:<2h99t5Fa1843U1@uni-berlin.de>...[color=blue]
> "Lauren Quantrell" <laurenquantrell@hotmail.com> wrote in message
> news:47e5bd72.0405220659.53eee85e@posting.google.c om...[color=green]
> > Tim,
> > This is how I have done it.
> > Create a stored procedure named "GetEMailAddresses"
> > Create a function to loop through the stored procedure.
> > Code is below. I hope this helps.
> > lq
> >
> >[/color]
>
> If you're using sql server and you have permissions to do so I recommend
> configuring mail on the server instead of the client. You only have to
> configure it once and thereafter it will work for everyone - even if you
> decide to move to a new front-end. You don't need to worry about references,
> libraries, outlook versions etc. etc. It's a lot easier to set up and to
> administer.[/color]
John Winterbottom
Guest
 
Posts: n/a
#9: Nov 13 '05

re: How to send email via code in an Access Project?


"Lauren Quantrell" <laurenquantrell@hotmail.com> wrote in message
news:47e5bd72.0405221903.1d1aea16@posting.google.c om...[color=blue]
> John,
> Is there a nutshell version of how this is done? I've never tried
> doing this. How does the server resolve issues involving the sender
> and return address for a sender's e-mail if everyone is hitting the
> same server-side mail client?
> lq
>[/color]

Although you can use the built-in SQLMail, I prefer to use the xpsmtp
extended stored procedure - this is a custom extended stored procedure (dll)
written to send mail from sql server - more details at
http://www.sqldev.net/xp/xpsmtp.htm This gets around the need to have a
MAPI client on the server. So far we haven't had any problems, except for
sending attachments - for attachments you have to figure out a way to map a
unc path back to the client. We haven't seen any problems with multiple
users hitting the server at the same time - each message gets sent with the
correct to and from addresses.


Tim Smallwood
Guest
 
Posts: n/a
#10: Nov 13 '05

re: How to send email via code in an Access Project?


I'm sorry Tony.. It was a link you provided to
http://www.joelonsoftware.com that I was meaning to thank you for..


Tim

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Tim Smallwood
Guest
 
Posts: n/a
#11: Nov 13 '05

re: How to send email via code in an Access Project?



Laureen,

Thank you so much.. I'll save this and try it out later..

Tim

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Tony Toews
Guest
 
Posts: n/a
#12: Nov 13 '05

re: How to send email via code in an Access Project?


Tim Smallwood <dotnettim@netscape.net> wrote:
[color=blue]
>I'm sorry Tony.. It was a link you provided to
>http://www.joelonsoftware.com that I was meaning to thank you for..[/color]

Gotcha. Yes, I quite like visiting that website myself. Interesting stuff.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Closed Thread


Similar Microsoft Access / VBA bytes