|
[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. |
|
|
|
|
Asked by joepinter in Access Coding/Macros, Outlook Groupware Software, Visual Basic v1.0.5.x
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
|
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625