Hi there, I have managed to find a way to loop through a recordset as defined by the current reports record source and filter, and to read an invoice's email field and send that specific invoice to that email. The problem I have though is that the email client will open up (Eudora in this case) and will prepare the email completely, except it won't automatically send the email. I must hit send. Now, I'm not lazy, but I don't want to do this. This procedure really slows down the system and is unbearable to run at points as I still have to sit here and hit send everytime so I can't leave my desk.
Here is my code:
Private Sub Email_Click()
On Error Resume Next
'Find the recordset that appears to the user.
Dim strTo As String
Dim strTitle As String
Dim strMessage As String
Dim Query
Query = Left(Reports("ClosedRequests").RecordSource, Len(Reports("ClosedRequests").RecordSource) - 2) & " AND " & Reports("ClosedRequests").Filter
Dim RsMyRS As DAO.Recordset
Set RsMyRS = CurrentDb.OpenRecordset(Query)
Dim SRID
RsMyRS.MoveFirst
'Read address to email, then send an email based on the settings the user chose before opening the report. Settings
'Are in underlying textboxs on this report for reference.
Do While Not (RsMyRS.EOF)
SRID = RsMyRS![SR#]
RsMyRS.MoveNext
DoCmd.OpenReport "Invoice", acViewPreview, , "SRID=" & SRID
strTo = Reports("Invoice")![E-mail Address]
strTitle = Me!Subject & SRID
strMessage = Me!Body
DoCmd.SendObject acSendReport, "Invoice", acFormatPDF, strTo, , , strTitle, strMessage
DoCmd.Close acReport, "Invoice"
If MsgBox("Click when ready to send next.", vbOKOnly) <> vbOK Then Exit Sub
Loop
'Finish Off.
RsMyRS.Close
End Sub
Everything works perfectly. I just imagine I need one more line of code to completely automate the process so I don't have to be involved once it starts. If anyone knows any methods of accomplishing it that would help a lot! Thanks!
Here is my code:
Private Sub Email_Click()
On Error Resume Next
'Find the recordset that appears to the user.
Dim strTo As String
Dim strTitle As String
Dim strMessage As String
Dim Query
Query = Left(Reports("ClosedRequests").RecordSource, Len(Reports("ClosedRequests").RecordSource) - 2) & " AND " & Reports("ClosedRequests").Filter
Dim RsMyRS As DAO.Recordset
Set RsMyRS = CurrentDb.OpenRecordset(Query)
Dim SRID
RsMyRS.MoveFirst
'Read address to email, then send an email based on the settings the user chose before opening the report. Settings
'Are in underlying textboxs on this report for reference.
Do While Not (RsMyRS.EOF)
SRID = RsMyRS![SR#]
RsMyRS.MoveNext
DoCmd.OpenReport "Invoice", acViewPreview, , "SRID=" & SRID
strTo = Reports("Invoice")![E-mail Address]
strTitle = Me!Subject & SRID
strMessage = Me!Body
DoCmd.SendObject acSendReport, "Invoice", acFormatPDF, strTo, , , strTitle, strMessage
DoCmd.Close acReport, "Invoice"
If MsgBox("Click when ready to send next.", vbOKOnly) <> vbOK Then Exit Sub
Loop
'Finish Off.
RsMyRS.Close
End Sub
Everything works perfectly. I just imagine I need one more line of code to completely automate the process so I don't have to be involved once it starts. If anyone knows any methods of accomplishing it that would help a lot! Thanks!