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 and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Tags: , , , , ,

Bcc messages from Access 03 to Outlook using query





 
 
Thread Tools Display Modes
  #1  
Old November 26th 06, 11:19 AM posted to microsoft.public.outlook.program_vba
Ultraviolet47
external usenet poster
 
Posts: 6
Default Bcc messages from Access 03 to Outlook using query

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

Ads
  #2  
Old November 26th 06, 01:05 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,299
Default Bcc messages from Access 03 to Outlook using query

If you looked in the object browser at the Outlook object library, you'd see that the method is Recipients.Add, not AddMailList.

The default Type for a recipient added with Recipients.Add is olTo.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Ultraviolet47" wrote in message oups.com...
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?


  #3  
Old November 26th 06, 06:03 PM posted to microsoft.public.outlook.program_vba
Ultraviolet47
external usenet poster
 
Posts: 6
Default Bcc messages from Access 03 to Outlook using query

Hi

I need to call up the "email" field from a query and insert these into
Bcc field. if I use that code, it just inserts the word "email" a few
dozen times (but it does go in the bcc fied at least!) I think because
it's a query, it needs the maillist?

Before, MyMail.Recipients.AddMailList("email") worked fine, but I just
needed it in the Bcc field, not the To field.


Any advice?

  #4  
Old November 26th 06, 06:18 PM posted to microsoft.public.outlook.program_vba
Ultraviolet47
external usenet poster
 
Posts: 6
Default Bcc messages from Access 03 to Outlook using query

Sorry, that's

MyMail.Recipients.Add MailList("email")

worked before, but put it in the To field.

  #5  
Old November 26th 06, 11:04 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,299
Default Bcc messages from Access 03 to Outlook using query

You already answered your own question in your original post. Look at your olBcc statement.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Ultraviolet47" wrote in message ups.com...
Sorry, that's

MyMail.Recipients.Add MailList("email")

worked before, but put it in the To field.

  #6  
Old November 27th 06, 09:25 AM posted to microsoft.public.outlook.program_vba
Ultraviolet47
external usenet poster
 
Posts: 6
Default Bcc messages from Access 03 to Outlook using query

Yes, but if I use the space between Add and MailList

Set objRecip = MyMail.Recipients.Add MailList("email")
objRecip.Type = olBCC
says expected end of statement and syntax error

and

MyMail.Recipients.Add MailList("email")
objRecip.Type = olBCC
says invalid use of Null

What I am overlooking?

  #7  
Old November 27th 06, 12:20 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,299
Default Bcc messages from Access 03 to Outlook using query

This is the statement that instantiates MailList:

Set MailList = db.OpenRecordset("Qry_UpdatesOE")

Check the value that MailList("email") returns and see http://support.microsoft.com/Default.aspx?kbid=290658 for an example of DAO database syntax.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Ultraviolet47" wrote in message oups.com...
Yes, but if I use the space between Add and MailList

Set objRecip = MyMail.Recipients.Add MailList("email")
objRecip.Type = olBCC
says expected end of statement and syntax error

and

MyMail.Recipients.Add MailList("email")
objRecip.Type = olBCC
says invalid use of Null

What I am overlooking?

  #8  
Old November 28th 06, 10:15 PM posted to microsoft.public.outlook.program_vba
Ultraviolet47
external usenet poster
 
Posts: 6
Default Bcc messages from Access 03 to Outlook using query

Good grief, this is keeping me up at night!
I know the mail list query works, it's just dumping the darn thing
where I want it.
This is totally lost on me-I shall just settle for it being in the To
field and copy and paste it into the bcc field I think! My brain admits
defeat- lol

Thanks for everyone's help anyway

 




Thread Tools
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
using access query to populate outlook distribution list Iona Outlook - General Queries 0 July 11th 06 06:39 AM
How to send multiple messages without using BCC or CC? nws Outlook - General Queries 3 April 13th 06 11:01 AM
Configuration query in Outlook 2003 KiwiBrian Outlook - General Queries 1 February 5th 06 01:51 AM
import query into outlook calendar Sue Mosher [MVP-Outlook] Outlook - Calandaring 0 January 18th 06 10:24 PM
Running query from Access Form commmand using VBA code Berny Outlook and VBA 4 January 16th 06 02:12 PM


All times are GMT +1. The time now is 06:13 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2008 Outlook Banter, part of the NewsgroupBanter project.
The comments are property of their posters.
e Harmony - MPAA - Dominios - Mobile Phones - Vegas Hotel