driver7408
Registered User.
- Local time
- Yesterday, 18:40
- Joined
- Feb 7, 2010
- Messages
- 72
I am really new to VBA; having gotten by designing most of my database with macros so far.
I have a query that I designed that pulls up a list of people and their email addresses, as well as 4 other fields of information. The query has no Nulls anywhere. I need to send an email through Outlook occasionally when the query gets updated. I have a button assigned to do that. I need it to send the email to all of the people in the query at once, and combine all of their names in the 'To' field, separated by commas. I need the information from the 4 fields to go into the email. I don't care if the security box pops up once to allow sending the email, nor do I care if instead it just opens up outlook with the email ready to be sent.
The closest code I could find worked great, except the user has to click on the security permission for each email, because it was sending a separate email to each person, rather then combining all the recipients in the 'To' field.
I cannot download any add-ons to do this due to admin security constraints on our network.
Is there any way to modify this code to make it send the email in the manner in which I need it to?
Dim MyDb As DAO.Database
Dim rsEmail As DAO.Recordset
Dim sToName As String
Dim sSubject As String
Dim sMessageBody As String
Set MyDb = CurrentDb()
Set rsEmail = MyDb.OpenRecordset("EmailQuery", dbOpenSnapshot)
With rsEmail
.MoveFirst
Do Until rsEmail.EOF
If IsNull(.Fields(5)) = False Then
sToName = .Fields(5)
sSubject = "You have a new file waiting"
sMessageBody = "The File"&.Fields(2)&"is now available."&vbCrLf_
&"Date: "&.Fields(3)&vbCrLf_
&"Location: "&.Fields(4)
DoCmd.SendObject acSendNoObject, , , _
sToName, , , sSubject, sMessageBody, False, False
End If
.MoveNext
Loop
End With
Set MyDb = Nothing
Set rsEmail = Nothing
I have a query that I designed that pulls up a list of people and their email addresses, as well as 4 other fields of information. The query has no Nulls anywhere. I need to send an email through Outlook occasionally when the query gets updated. I have a button assigned to do that. I need it to send the email to all of the people in the query at once, and combine all of their names in the 'To' field, separated by commas. I need the information from the 4 fields to go into the email. I don't care if the security box pops up once to allow sending the email, nor do I care if instead it just opens up outlook with the email ready to be sent.
The closest code I could find worked great, except the user has to click on the security permission for each email, because it was sending a separate email to each person, rather then combining all the recipients in the 'To' field.
I cannot download any add-ons to do this due to admin security constraints on our network.
Is there any way to modify this code to make it send the email in the manner in which I need it to?
Dim MyDb As DAO.Database
Dim rsEmail As DAO.Recordset
Dim sToName As String
Dim sSubject As String
Dim sMessageBody As String
Set MyDb = CurrentDb()
Set rsEmail = MyDb.OpenRecordset("EmailQuery", dbOpenSnapshot)
With rsEmail
.MoveFirst
Do Until rsEmail.EOF
If IsNull(.Fields(5)) = False Then
sToName = .Fields(5)
sSubject = "You have a new file waiting"
sMessageBody = "The File"&.Fields(2)&"is now available."&vbCrLf_
&"Date: "&.Fields(3)&vbCrLf_
&"Location: "&.Fields(4)
DoCmd.SendObject acSendNoObject, , , _
sToName, , , sSubject, sMessageBody, False, False
End If
.MoveNext
Loop
End With
Set MyDb = Nothing
Set rsEmail = Nothing