Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / General MS Outlook Questions / November 2006

Tip: Looking for answers? Try searching our database.

Bcc messages from Access to Outlook based on query

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ultraviolet47 - 22 Nov 2006 20:11 GMT
Hi

I have code that opens up an email based on a query from Access. It
puts it in the To field, but it's a newsletter and needs to go in the
BCC field. I ahve tried placing BCC in various places, but no luck. ANy
ideas please?

Much appreciated!

Public Function SendEmailUpdates()

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
'Enter the subject line

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

' If there's no subject, quit.

If Subjectline$ = "" Then
   MsgBox "Email composition cancelled" & vbNewLine & vbNewLine & _
      "", vbCritical, "Outlook Email "
   Exit Function
End If

' Enter body text

BodyFile$ = InputBox$("Please enter the location of the filename of the
body of the message.", _
            "Enter location of .txt file")

' If there's no body, quit.

If BodyFile$ = "" Then
   MsgBox "Email composition cancelled" & vbNewLine & vbNewLine & _
        "", vbCritical, "Outlook Email"
   Exit Function
End If

' Check to make sure the file exists...
If fso.FileExists(BodyFile$) = False Then
   MsgBox "The body file cannot be found, please check the location. "
& vbNewLine & vbNewLine & _
          "Email composition cancelled", vbCritical, "No file found."
   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_UpdatesOE")

' 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
       ' We need to move it BEFORE we start the loop, since
       ' we don't want to make a bunch of e-mails, we just want one.

       Set MyMail = MyOutlook.CreateItem(olMailItem)

        ' now, this is the meat and potatoes.
        ' this is where we loop through our list of addresses,
        ' and we add them to the RECIPIENTS collection

   Do Until MailList.EOF

           ' This adds the address to the list of recipients

         MyMail.Recipients.Add MailList("email")

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

Loop

           ' And now that we've addressed it, we can finish composing
the rest of the fields.

           'This gives it a subject

           MyMail.Subject = Subjectline$

           'This gives it the body
           MyMail.Body = MyBodyText

           ' This sends it!

           'MyMail.Send

           MyMail.Display

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
Ultraviolet47 - 22 Nov 2006 20:13 GMT
PS-Outlook and Access 2003
Ken Slovak - [MVP - Outlook] - 22 Nov 2006 20:30 GMT
Get a Recipient object when you add to the Recipients collection. Set that
Recipient.Type = olBCC. Make sure you also have a To address, otherwise the
email may not go out or be rejected.

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

> Hi
>
[quoted text clipped - 135 lines]
>
> End Function
Ultraviolet47 - 22 Nov 2006 21:46 GMT
Hi

Thanks for that. Any idea how to set the object? I've tried bits of
code I've found, but can't get them to fit together?

 MyMail.Recipients.Add MailList("email")
         Dim olookRecipient As Object 'Outlook.Recipient
          Set olookRecipient = obEmail.Recipients
         Recipient.Type = olBCC

Thanks very much:)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.