[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

Populate Email Recipients in Outlook from 2003 Access Database Query using VBA

Asked by joepinter in Access Coding/Macros, Outlook Groupware Software, Visual Basic v1.0.5.x

Tags: Microsoft Access, Microsoft Outlook, VBA, Access Visual Basic

I am trying to develop a VBA script that will identify certain users through a SQL query and then generate an email to all of them. I have the query working, however I am unsure of how to remove the email address from the SQL recordset and place them in the 'To' field. I would if possible also like to separate each email with commas so that there is no need to adjust this field once the data has been entered.

I have added OutLook to the reference library and the SQL statement works but it sill locks up when run. Can anyone tell me if there is a better way to do this or whats wrong with the way I am doing it?

Bellow I have listed some sample code to try and illustrate what I am attempting.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
Private Sub CommandEmail_Click()
Dim rs AS DAO.Recordset
Dim db AS Database
Dim OrgID AS String
Dim appOutLook As Outlook.Application
Dim MailOutLook As outlook.MailItem
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
ME.OrgID = OrgID
SQL="SELECT Customer_Email From tblCustomer WHERE Customer_Organization='"OrgID"';"
On Error Resume Next
'Open DB
Set db = CurrentDB
Set rs = db.Recordsets(SQL) 
Do Until rs.EOF
Recipient = rs!Customer_Email & ", "
rs.MoveNext
Loop
rs.close
db.close 
MailOutLook.HTMLBody = "Dear Customer,"
'Message Routing Information
MailOutLook.Display
MailOutLook.To=Recipient
MailOutLook.CC=Forward
MailOutLook.Subject=EmailSubject 
Driver Exit:
On Error Resume Next
Set MailOutLook = Nothing
Set appOutLook = Nothing
Exit Sub
End Sub
[+][-]11/05/09 01:25 PM, ID: 25754215Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 01:26 PM, ID: 25754225Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 01:43 PM, ID: 25754377Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625