Computer Learning Zone CLZ Access Excel Word Windows

When I first looked back at the Earth, standing on the Moon, I cried.

-Alan Shepard
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Microsoft Access Email Seminar    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Email Seminar
James Comninellis 

9 years ago
Hi,
I have a specific VBA question. This is all good content but it's almost more than I need. I want to place a button in a form that will take all the emails in a query and place them in the "To" or "Bcc" field of an email. I have been working with the following code but with no success yet:

Private Sub Command69_Click()
Dim oOutlook As Outlook.Application
Dim oEmailItem As MailItem
Dim rs As Recordset
Dim recipientList As String
If oOutlook Is Nothing Then
    Set oOutlook = New Outlook.Application
End If

Set oEmailItem = oOutlook.CreateItem(olMailItem)
With oEmailItem
        Set rs = CurrentDb.OpenRecordset("SELECT Email FROM ContactT")
        If rs.RecordCount > 0 Then
        rs.MoveFirst
        Do Until rs.EOF
            If IsNull(rs!Email) Then
                rs.MoveNext
            Else
                contactEmail = contactEmail & rs!Email & ";"
                .To = contactEmail
                rs.MoveNext
            End If
        Loop
        Else
            MsgBox "No email addresses available"
        End If
        
        
.To = ""
.Display
End With
Set oEmailItem = Nothing
Set oOutlook = Nothing
End Sub

This code (if it worked) would send to all my contacts, which is not what I'm aiming for, but I would put in a proper query is I could get this off the ground. Thanks!


Reply from Alex Hedley:

So you have
.To = contactEmail

Then near the end you have
.To = ""

This will clear all your looping work.

If it's easier to follow make a string with all the To people in your loop, then set your .To to your string at the end.
You can then Debug.Print(string) in various places when testing.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Microsoft Access Email Seminar.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/10/2026 8:43:55 AM. PLT: 0s