![]() |
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. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
Hi all
Someone on the general board pointed me in this direction. I have the following code to use the emails returned from a query, open outlook and bcc them. It gives a run time error sayinig it doesn't support the property or method for Set objRecip = MyMail.Recipients.AddMailList("email") objRecip.Type = olBCC but I've checked all the object libraries I can find that are applicable to this-anyone have any idea which ones I might be missing? I have the offfice and outlook ones. I also need to set a To address, so some mailboxes won't reject them-does any have any idea how to do that? Any help greatly appeciated. 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 ' If file exists, open it. Set MyBody = fso.OpenTextFile(BodyFile, ForReading, False, TristateUseDefault) ' and read it into a variable. MyBodyText = MyBody.ReadAll ' and close the file. MyBody.Close ' Open Outlook 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 ' Need to move it BEFORE the loop is started, as we don't want to make separate emails, just one. Set MyMail = MyOutlook.CreateItem(olMailItem) 'Loop through list of addresses, ' and add them to the RECIPIENTS list Do Until MailList.EOF ' This adds the address to the list of recipients Set objRecip = MyMail.Recipients.AddMailList("email") objRecip.Type = olBCC 'And next ones MailList.MoveNext Loop ' 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 'Show email MyMail.Display Loop 'Cleanup Set MyMail = Nothing Set MyOutlook = Nothing MailList.Close Set MailList = Nothing db.Close Set db = Nothing End Function |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
using access query to populate outlook distribution list | Iona | Outlook - General Queries | 0 | July 11th 06 07:39 AM |
How to send multiple messages without using BCC or CC? | nws | Outlook - General Queries | 3 | April 13th 06 12:01 PM |
Configuration query in Outlook 2003 | KiwiBrian | Outlook - General Queries | 1 | February 5th 06 02:51 AM |
import query into outlook calendar | Sue Mosher [MVP-Outlook] | Outlook - Calandaring | 0 | January 18th 06 11:24 PM |
Running query from Access Form commmand using VBA code | Berny | Outlook and VBA | 4 | January 16th 06 03:12 PM |