Hi Guys,
Background - I want to send an email/s to various recipents email addresses based on a query result. I've created separate queries for each month but ideally would like to set the parameters to choose a month within the code, however although i cant find anything to do this yet the code below lets me send an email based on the query result for a single month. This is working great at the mo, but I now need to send an attachment with the email. I'd really appreciate it if someone would cast their eye over the code listed below and see if they can find a solution.
Private Sub email_attached_Click()
Dim MyDb As DAO.Database
Dim rsEmail As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim prm As DAO.Parameter
Dim sToName As String
Dim sSubject As String
Dim sMessageBody As String
Set MyDb = CurrentDb
Set qdf = MyDb.QueryDefs("qryrecipients_emails_mar11")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next
Set rsEmail = qdf.OpenRecordset()
With rsEmail
.MoveFirst
Do Until rsEmail.EOF
If IsNull(.Fields(0)) = False Then
sToName = .Fields(0)
sSubject = "See Attachment"
sMessageBody = "Hi," & vbCrLf & vbCrLf & "Please see attached." & vbCrLf & vbCrLf & "Regards," & vbCrLf & vbCrLf & "Paul"
DoCmd.SendObject acSendNoObject, , , sToName, , , sSubject, sMessageBody, False, False
End If
.MoveNext
Loop
End With
Set MyDb = Nothing
Set rsEmail = Nothing
End Sub
Many thanks for looking.
Regards,
Paul
Background - I want to send an email/s to various recipents email addresses based on a query result. I've created separate queries for each month but ideally would like to set the parameters to choose a month within the code, however although i cant find anything to do this yet the code below lets me send an email based on the query result for a single month. This is working great at the mo, but I now need to send an attachment with the email. I'd really appreciate it if someone would cast their eye over the code listed below and see if they can find a solution.
Private Sub email_attached_Click()
Dim MyDb As DAO.Database
Dim rsEmail As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim prm As DAO.Parameter
Dim sToName As String
Dim sSubject As String
Dim sMessageBody As String
Set MyDb = CurrentDb
Set qdf = MyDb.QueryDefs("qryrecipients_emails_mar11")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next
Set rsEmail = qdf.OpenRecordset()
With rsEmail
.MoveFirst
Do Until rsEmail.EOF
If IsNull(.Fields(0)) = False Then
sToName = .Fields(0)
sSubject = "See Attachment"
sMessageBody = "Hi," & vbCrLf & vbCrLf & "Please see attached." & vbCrLf & vbCrLf & "Regards," & vbCrLf & vbCrLf & "Paul"
DoCmd.SendObject acSendNoObject, , , sToName, , , sSubject, sMessageBody, False, False
End If
.MoveNext
Loop
End With
Set MyDb = Nothing
Set rsEmail = Nothing
End Sub
Many thanks for looking.

Regards,
Paul