dc2000
02-15-2009, 11:38 PM
Hi everyone:
I'm not really a VBA programmer so your help will be greatly appreciated. I was hoping to automate a task of emailing notifications to a list of our clients. For that I made a table with all the email addresses and use the following script to email them:
Private Sub SendEmails_Click()
Dim Name As String
Dim email As String
Dim templ As String
Dim msg As String
Dim subj As String
Dim rst As New ADODB.Recordset
Dim rst_d As New ADODB.Recordset
Dim ver As String
'Update version
ver = "1.1"
'Select text for message
rst_d.Open "SELECT * FROM Data WHERE ID=2", CurrentProject.Connection
templ = Trim(Nz(rst_d.Fields("text"), ""))
'Select emails
rst.Open "SELECT emails.ID, emails.email, emails.name FROM emails", CurrentProject.Connection
'Go through all email addresses
Do While Not rst.EOF
email = Trim(Nz(rst.Fields("email"), ""))
Name = Trim(Nz(rst.Fields("name"), ""))
subj = "Software Update Notification"
'Apply changes
msg = templ
If Name <> "" Then
msg = Replace(msg, "%NAME%", " " & Name)
Else
msg = Replace(msg, "%NAME%", "")
End If
msg = Replace(msg, "%VERSION%", ver)
'Send email
DoCmd.SendObject , , acFormatTXT, _
email, , , subj, msg, 0
'Go to next record
rst.MoveNext
Loop
'Show message
MsgBox "Your email messages were sent. Check Outbox in the Outlook Express..." _
, vbInformation Or vbOKOnly
End Sub
It works fine except that all emails are sent from the default email account. We have 3 other accounts set up in Outlook Express. How to make emails to be sent from another email account?
I'm not really a VBA programmer so your help will be greatly appreciated. I was hoping to automate a task of emailing notifications to a list of our clients. For that I made a table with all the email addresses and use the following script to email them:
Private Sub SendEmails_Click()
Dim Name As String
Dim email As String
Dim templ As String
Dim msg As String
Dim subj As String
Dim rst As New ADODB.Recordset
Dim rst_d As New ADODB.Recordset
Dim ver As String
'Update version
ver = "1.1"
'Select text for message
rst_d.Open "SELECT * FROM Data WHERE ID=2", CurrentProject.Connection
templ = Trim(Nz(rst_d.Fields("text"), ""))
'Select emails
rst.Open "SELECT emails.ID, emails.email, emails.name FROM emails", CurrentProject.Connection
'Go through all email addresses
Do While Not rst.EOF
email = Trim(Nz(rst.Fields("email"), ""))
Name = Trim(Nz(rst.Fields("name"), ""))
subj = "Software Update Notification"
'Apply changes
msg = templ
If Name <> "" Then
msg = Replace(msg, "%NAME%", " " & Name)
Else
msg = Replace(msg, "%NAME%", "")
End If
msg = Replace(msg, "%VERSION%", ver)
'Send email
DoCmd.SendObject , , acFormatTXT, _
email, , , subj, msg, 0
'Go to next record
rst.MoveNext
Loop
'Show message
MsgBox "Your email messages were sent. Check Outbox in the Outlook Express..." _
, vbInformation Or vbOKOnly
End Sub
It works fine except that all emails are sent from the default email account. We have 3 other accounts set up in Outlook Express. How to make emails to be sent from another email account?