I have a report that I run which is grouped on Organization Name. I have some VBA (thanks to this forum) which splits this report into individual reports for each Organization and drops the reports into a folder. Each report is named with the Organization Name. Let's call this Step 1.
So now I end up with a bunch of reports in a folder (hundreds of reports). I need to email each report to the respective organization. As part of Step 1 I create a table of each Organization Name which is used as part of the looping and file-naming criteria. I can imagine a scenario where I connect an email address to each Organization in the table so that after the report is PDFed it gets emailed to the address. Note that I said I can IMAGINE this scenario. I have no idea if Access is the tool for this job.
However I can also see a scenario where I take some other program and use it to send the PDFs. I can even put the PDFs on an FTP server and email each organization a link to their PDF (security issues aside) - I can use a simple mail merge for this.
The simplest solution is for me to insert the little email doodad into the following code. You tell me how to do that I will not just give you a tek-tips star, I will give you a real-life star.
I joined this forum in 2005. I am still a hack.
So now I end up with a bunch of reports in a folder (hundreds of reports). I need to email each report to the respective organization. As part of Step 1 I create a table of each Organization Name which is used as part of the looping and file-naming criteria. I can imagine a scenario where I connect an email address to each Organization in the table so that after the report is PDFed it gets emailed to the address. Note that I said I can IMAGINE this scenario. I have no idea if Access is the tool for this job.
However I can also see a scenario where I take some other program and use it to send the PDFs. I can even put the PDFs on an FTP server and email each organization a link to their PDF (security issues aside) - I can use a simple mail merge for this.
The simplest solution is for me to insert the little email doodad into the following code. You tell me how to do that I will not just give you a tek-tips star, I will give you a real-life star.
Code:
Private Sub Command3_Click()
Const Folder = "C:\path\"
Const Domain = "qrySPU04ListOfOrgs"
'Domain can be table name, query name, or sql statement that provides the values to loop
Const LoopedField = "MinOfID"
Const NewFileName = "UserOrg"
Const ReportName = "rpt_qrySPU03"
Dim rs As DAO.Recordset
Dim LoopedFieldValue As Long
Dim FileName As String
Dim FullPath As String
Dim strWhere As String
Dim NewNewFileName As String
Set rs = CurrentDb.OpenRecordset(Domain)
Do While Not rs.EOF
LoopedFieldValue = rs.Fields(LoopedField)
NewNewFileName = rs.Fields(NewFileName)
FileName = NewNewFileName & ".PDF"
'The field may be a text field. It then must be surrounded in singlequotes. If so uncomment below
'LoopedFieldValue = "'" & LoopedFieldValue & "'"
FullPath = Folder & FileName
strWhere = LoopedField & " = " & LoopedFieldValue
Debug.Print FullPath
Debug.Print strWhere
DoCmd.OpenReport ReportName, acViewPreview, , strWhere
DoCmd.OutputTo acOutputReport, ReportName, acFormatPDF, FullPath
DoCmd.Close acReport, ReportName
rs.MoveNext
Loop
End Sub
I joined this forum in 2005. I am still a hack.