A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook - General Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Have all email addresses in one email using Outlook called from Access 03



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old November 17th 06, 07:45 PM posted to microsoft.public.outlook
Ultraviolet47
external usenet poster
 
Posts: 6
Default Have all email addresses in one email using Outlook called from Access 03

Hi all

I'm using Access and Outlook 03.


I found some code that works-sort of! I am looking to call up a query
in Access and all the email addresses returned in this query, put in
the bcc field of one email in Outlook.


At the mo, it finds the email addresses, but pops up one new message
for each email address, e.g 100 emails=100 popped up messages!


Is there anyway to avoid this loop and put all email addresses in one
messages bcc field?


Public Function SendEmail()


Dim db As DAO.Database
Dim MailList As DAO.Recordset
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim Subjectline As String
Dim BodyFile As String
Dim fso As FileSystemObject
Dim MyBody As TextStream
Dim MyBodyText As String


Set fso = New FileSystemObject


' First, we need to know the subject.
' We can't very well be sending around blank messages...


Subjectline$ = InputBox$("Please enter the subject line for this
mailing.", _
"We Need A Subject Line!")


' If there's no subject, call it a day.


If Subjectline$ = "" Then
MsgBox "No subject line, no message." & vbNewLine & vbNewLine & _
"Quitting...", vbCritical, "E-Mail Merger"
Exit Function
End If


' Now we need to put something in our letter...


BodyFile$ = InputBox$("Please enter the filename of the body of the
message.", _
"We Need A Body!")


' If there's nothing to say, call it a day.


If BodyFile$ = "" Then
MsgBox "No body, no message." & vbNewLine & vbNewLine & _
"Quitting...", vbCritical, "I Ain't Got No-Body!"
Exit Function
End If


' Check to make sure the file exists...
If fso.FileExists(BodyFile$) = False Then
MsgBox "The body file isn't where you say it is. " & vbNewLine &
vbNewLine & _
"Quitting...", vbCritical, "I Ain't Got No-Body!"
Exit Function
End If


' Since we got a file, we can open it up.
Set MyBody = fso.OpenTextFile(BodyFile, ForReading, False,
TristateUseDefault)


' and read it into a variable.
MyBodyText = MyBody.ReadAll


' and close the file.
MyBody.Close


' Now, we open Outlook for our own device..
Set MyOutlook = New Outlook.Application


' Set up the database and query connections


Set db = CurrentDb()


Set MailList = db.OpenRecordset("Qry_EmailrenewalsOE")


' now, this is the meat and potatoes.
' this is where we loop through our list of addresses,
' adding them to e-mails and sending them.


Do Until MailList.EOF


' This creates the e-mail


Set MyMail = MyOutlook.CreateItem(olMailItem)


' This addresses it
MyMail.Bcc = MailList("Email")


'This gives it a subject
MyMail.Subject = Subjectline$


'This gives it the body
MyMail.Body = MyBodyText


' This sends it!


'MyMail.Send


MyMail.Display


'And on to the next one...
MailList.MoveNext


Loop


'Cleanup after ourselves


Set MyMail = Nothing


'Uncomment the next line if you want Outlook to shut down when its
done.
'Otherwise, it will stay running.


'MyOutlook.Quit
Set MyOutlook = Nothing


MailList.Close
Set MailList = Nothing
db.Close
Set db = Nothing


End Function


Thanks guys!

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A program is trying to access email addresses you have stored in . Fruranski Outlook and VBA 1 June 19th 06 02:31 PM
Help-Error msg popup "A program is trying to access email addresses. . ' WF Outlook - General Queries 1 April 29th 06 02:08 AM
How do I import email addresses from an Access table? Chris Outlook - Using Contacts 1 April 7th 06 02:58 PM
How to Disable Message, "....trying to access email addresses..." fred Outlook - Using Forms 5 March 28th 06 12:44 AM
program trying to access email addresses Joy Waggoner Outlook - General Queries 2 March 16th 06 11:59 PM


All times are GMT +1. The time now is 11:38 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.