DataBase - Exporting Report from Access into PDF

Asked By Erick C
30-Jan-10 05:46 PM
Hi everybody.
I am hoping someone may be able to help me out.  I have a database
report that I want to export into PDF for each individual customer.
Basically, I want to set up a button on my form that will allow the
user to pick a location to save the files and then create a PDF based
on a report that I have saved in Access for each customer
individually.  I have been looking around online for a while and I
have been trying a few different things with not much success.
I had some code from Ken Snell that worked great for looping through
customer numbers and exporting an excel file for each individual
customer.  I tried to do a bit of modification to this code and add in
the OutputTo command with no luck.  Since the code uses a "dummy"
query to grab the information that is changing with each customer, I
do not know if I can have the properties of the report change every
time this source data changes.
I am trying to work with Stephen Leban's A2000ReportToPDF database
right now, but it is far more advanced than my puny range of code
knowledge will allow me to comprehend.
Is there anyone who has created something like this before?  Can it be
done?  Can someone help me out or point me in the right direction?
Thanks!

Here is the code that I am working with right now:

Dim qdf As DAO.QueryDef
Dim dbs As DAO.Database
Dim rstMgr As DAO.Recordset, rstMgr1 As DAO.Recordset
Dim strSQL As String, strTemp As String, strMgr As String
Dim strPathFile As String, strFile As String, strPath As String
Dim strTable As String, strBrowseMsg As String
Dim blnHasFieldNames As Boolean
strBrowseMsg = "Select the folder where the files will be created:"
strPath = BrowseFolder(strBrowseMsg)
If strPath = "" Then
MsgBox "No folder was selected.", vbOK, "No Selection"
Exit Sub
End If
Const strQName As String = "zExportQuery"
Set dbs = CurrentDb
' Create temporary query that will be used for exporting data;
' we give it a dummy SQL statement initially (this name will
' be changed by the code to conform to each manager's identification)
strTemp = dbs.TableDefs(0).Name
strSQL = "SELECT * FROM [" & strTemp & "] WHERE 1=0;"
Set qdf = dbs.CreateQueryDef(strQName, strSQL)
qdf.Close
strTemp = strQName
' *** code to set strSQL needs to be changed to conform to your
' *** database design -- ManagerID and EmployeesTable need to
' *** be changed to your table and field names
' Get list of ManagerID values -- note: replace my generic table and
Field names
' with the real names of the EmployeesTable table and the ManagerID
Field
strSQL = " SELECT DISTINCT BNY Acct# FROM [Customers_To_Email];"
Set rstMgr = dbs.OpenRecordset(strSQL, dbOpenDynaset, dbReadOnly)
' Now loop through list of ManagerID values and create a query foreach
ManagerID
' so that the data can be exported -- the code assumes that the actual
names
' of the managers are in a lookup table -- again, replace generic
names with
' real names of tables and fields
If rstMgr.EOF = False And rstMgr.BOF = False Then
rstMgr.MoveFirst
Do While rstMgr.EOF = False
' *** code to set strMgr needs to be changed to conform to your
' *** database design -- ManagerNameField, ManagersTable, and
' *** ManagerID need to be changed to your table and field names
' *** be changed to your table and field names
strMgr = DLookup("BNY Acct#", "Customers_To_Email", _
' *** code to set strSQL needs to be changed to conform to your
' *** database design -- ManagerID and EmployeesTable need to
' *** be changed to your table and field names
strSQL = "SELECT * FROM [Customers_To_Email] WHERE " & _
Set qdf = dbs.QueryDefs(strTemp)
qdf.Name = "q_" & strMgr
strTemp = qdf.Name
qdf.SQL = strSQL
qdf.Close
Set qdf = Nothing
strFile = Format$(Date, "Medium Date") & " " & strMgr &
strPathFile = strPath & "\" & strFile
DoCmd.OutputTo acOutputReport, [Sweep_Report_For_Email], _
acFormatPDF, strTemp, strPathFile
rstMgr.MoveNext
Loop
End If
rstMgr.Close
Set rstMgr = Nothing
dbs.QueryDefs.Delete strTemp
dbs.Close
Set dbs = Nothing
MsgBox "Individual Files Created.", vbOK, "Status"

End Sub
RtItem.EMBEDOBJECT
(1)
Session.GETDATABASE
(1)
CustomerListBox.ListCount
(1)
DoCmd.TransferSpreadsheet
(1)
ConvertReportToPDF
(1)
DoCmd.OpenReport
(1)
A2000ReportToPDF
(1)
DoCmd.OutputTo
(1)
  Gina Whipp replied to Erick C
29-Jan-10 08:59 PM
Erick,

Try...

'Posted by ADezii 5.23.2009 on bytes.com
'Modified by Gina Whipp 11.4.2009 to OutputTo Multiple Files
'Tested in Access 2003

Dim intCounter As Integer
Dim cboCode As ComboBox

Set cboCode = Me![YourControl]

'If Your Data Type is Numeric
For intCounter = 0 To cboCode.ListCount - 1
DoCmd.OpenReport "YourReport", acViewPreview, , "[YourFieldControlSource]
= " & cboCode.ItemData(intCounter)
DoEvents
DoCmd.OutputTo acReport, "YourReport", acFormatRTF,
DoCmd.Close acReport, "YourReport"
Next


'If Your Data Type is a String
For intCounter = 0 To cboCode.ListCount - 1
DoCmd.OpenReport "YourReport", acViewPreview, , "[YourFieldControlSource]
= '" &
cboCode.ItemData(intCounter) & "'"
DoEvents
DoCmd.OutputTo acReport, "YourReport", acFormatRTF,
DoCmd.Close acReport, "YourReport"
Next

--
Gina Whipp
2010 Microsoft MVP (Access)

II

http://www.regina-whipp.com/index_files/TipList.htm

Hi everybody.
I am hoping someone may be able to help me out.  I have a database
report that I want to export into PDF for each individual customer.
Basically, I want to set up a button on my form that will allow the
user to pick a location to save the files and then create a PDF based
on a report that I have saved in Access for each customer
individually.  I have been looking around online for a while and I
have been trying a few different things with not much success.
I had some code from Ken Snell that worked great for looping through
customer numbers and exporting an excel file for each individual
customer.  I tried to do a bit of modification to this code and add in
the OutputTo command with no luck.  Since the code uses a "dummy"
query to grab the information that is changing with each customer, I
do not know if I can have the properties of the report change every
time this source data changes.
I am trying to work with Stephen Leban's A2000ReportToPDF database
right now, but it is far more advanced than my puny range of code
knowledge will allow me to comprehend.
Is there anyone who has created something like this before?  Can it be
done?  Can someone help me out or point me in the right direction?
Thanks!

Here is the code that I am working with right now:

Dim qdf As DAO.QueryDef
Dim dbs As DAO.Database
Dim rstMgr As DAO.Recordset, rstMgr1 As DAO.Recordset
Dim strSQL As String, strTemp As String, strMgr As String
Dim strPathFile As String, strFile As String, strPath As String
Dim strTable As String, strBrowseMsg As String
Dim blnHasFieldNames As Boolean
strBrowseMsg = "Select the folder where the files will be created:"
strPath = BrowseFolder(strBrowseMsg)
If strPath = "" Then
MsgBox "No folder was selected.", vbOK, "No Selection"
Exit Sub
End If
Const strQName As String = "zExportQuery"
Set dbs = CurrentDb
' Create temporary query that will be used for exporting data;
' we give it a dummy SQL statement initially (this name will
' be changed by the code to conform to each manager's identification)
strTemp = dbs.TableDefs(0).Name
strSQL = "SELECT * FROM [" & strTemp & "] WHERE 1=0;"
Set qdf = dbs.CreateQueryDef(strQName, strSQL)
qdf.Close
strTemp = strQName
' *** code to set strSQL needs to be changed to conform to your
' *** database design -- ManagerID and EmployeesTable need to
' *** be changed to your table and field names
' Get list of ManagerID values -- note: replace my generic table and
Field names
' with the real names of the EmployeesTable table and the ManagerID
Field
  Erick C replied to Gina Whipp
31-Jan-10 12:59 AM
Gina -
Thanks for the response.
I tried to use your code, but I have run into some problems.  I do not
know if I actually filled everything out correctly (which I probably
did not since I am still kind of new at this stuff).
Here is the code that I tried to use, it gave me a compile error,
saying "Can't find project or library." and the debugger highlights
Format in the docmd.OutputTo line.

Private Sub CreatePDF_Click()

Dim intCounter As Integer
Dim cboCode As ComboBox


Set cboCode =3D Me![Customers_To_Email]

'If Your Data Type is a String
For intCounter =3D 0 To cboCode.ListCount - 1
DoCmd.OpenReport "Sweep_Report_For_Email", acViewPreview, ,
& " '"
DoEvents
DoCmd.OutputTo acReport, "Sweep_Report_For_Email", acFormatRTF, "C:
\Users\Erick\Documents\export" & Format(intCounter, "000") & ".rtf"
DoCmd.Close acReport, "YourReport"
Next

End Sub


rce]
rce]
s
  Gina Whipp replied to Erick C
30-Jan-10 11:44 PM
Erick,

Before I adjust your code...  I thought you wanted to use Stephen Leban's
ReportToPDF?

--
Gina Whipp
2010 Microsoft MVP (Access)

II

http://www.regina-whipp.com/index_files/TipList.htm

Gina -
Thanks for the response.
I tried to use your code, but I have run into some problems.  I do not
know if I actually filled everything out correctly (which I probably
did not since I am still kind of new at this stuff).
Here is the code that I tried to use, it gave me a compile error,
saying "Can't find project or library." and the debugger highlights
Format in the docmd.OutputTo line.

Private Sub CreatePDF_Click()

Dim intCounter As Integer
Dim cboCode As ComboBox


Set cboCode = Me![Customers_To_Email]

'If Your Data Type is a String
For intCounter = 0 To cboCode.ListCount - 1
DoCmd.OpenReport "Sweep_Report_For_Email", acViewPreview, ,
& " '"
DoEvents
DoCmd.OutputTo acReport, "Sweep_Report_For_Email", acFormatRTF, "C:
\Users\Erick\Documents\export" & Format(intCounter, "000") & ".rtf"
DoCmd.Close acReport, "YourReport"
Next

End Sub
  Erick C replied to Gina Whipp
31-Jan-10 09:27 PM
Gina -

I tried to figure out how to use ReportToPDF because in my digging
around online it seemed to be mentioned as the best way to export
reports to PDF.  I do not have any preference as to where the code
comes from as long as it works correctly.  If I need to use
ReportToPDF then I will keep plugging away at his database to try and
get it to work, though as I mentioned earlier it is a bit complex for
my level of understanding.  I wanted to see if there was anyone who
had a code that achieved the same results that I could modify before I
spent a ton of effort trying to figure out the ReportToPDF database,
and eventually coming back here for help anyway.  I just came here
first, that is all.


's
s
e]
e]
  Gina Whipp replied to Erick C
31-Jan-10 06:20 PM
Erick,

I am here to help... so if step one is getting the ReportToPDF to work first
then lets do that...  What problems are you having getting that code to
work?  ANd where are you with it?  Have you copied it into a module?  Have
you put the .DLL's in place?  You get the idea...

--
Gina Whipp
2010 Microsoft MVP (Access)

II

http://www.regina-whipp.com/index_files/TipList.htm

Gina -

I tried to figure out how to use ReportToPDF because in my digging
around online it seemed to be mentioned as the best way to export
reports to PDF.  I do not have any preference as to where the code
comes from as long as it works correctly.  If I need to use
ReportToPDF then I will keep plugging away at his database to try and
get it to work, though as I mentioned earlier it is a bit complex for
my level of understanding.  I wanted to see if there was anyone who
had a code that achieved the same results that I could modify before I
spent a ton of effort trying to figure out the ReportToPDF database,
and eventually coming back here for help anyway.  I just came here
first, that is all.
  Erick C replied to Gina Whipp
02-Feb-10 01:58 PM
Hi Gnia -
I apologize for the delay in my response, busy time for me at work.
I cannot seem to get anything going with this ReportToPDF.  I do not
know what I am doing, or not doing.  I have no idea how to integrate
the code into my current database.  I am just plain lost and becoming
frustrated, sadly.
I have copied the database and the two DLL files into the same folder
in My Documents along with my created database that I am testing.  I
just do not know what I am doing wrong, or how I am supposed to use
this ReportToPDF database.
If I just open the ReportToPDF database and try to use the form and
press the "Click Here to Save this Report as a PDF document" button I
get an error saying SnapshotToPDF: 2213 - There was a problem
retrieving printer information for this object.  The object may have
been sent to a printer that is unavailable.
I cannot seem to figure out what printer this report is pointing at.
My default network printer is set up correctly.
I also imported all of the modules into my own database, then copied
the event procedure code attached to the "Click Here" button from
above.
I tried to modify a few things to get it to work, but nothing doing.
If I try to use the button, I get a Run time error '2465':  Microsoft
Office Access cannot find the field "I" referred to in your expression.
Here is the code I tried to use:

Private Sub cmdReportToPDF_Click()
' Save the Report as a PDF document.
' The selected report is first exported to Snapshot format.
' The Snapshot file is then broken out into its
' component Enhanced Metafiles(EMF), one for each page of the report.
' Finally, the EMF's are converted to PDF pages within the master
' PDF document.

' The function call is:
'Public Function ConvertReportToPDF( _
'Optional RptName As String =3D "", _
'Optional SnapshotName As String =3D "", _
'Optional OutputPDFname As String =3D "", _
'Optional ShowSaveFileDialog As Boolean =3D False, _
'Optional StartPDFViewer As Boolean =3D True, _
'Optional CompressionLevel As Long =3D 150, _
'Optional PasswordOpen As String =3D "", _
'Optional PasswordOwner As String =3D "", _
'Optional PasswordRestrictions As Long =3D 0, _
'Optional PDFNoFontEmbedding as Long =3D 0, _
'Optional PDFUnicodeFlags As Long =3D 0 _
') As Boolean

' RptName is the name of a report contained within this MDB
' SnapshotName is the name of an existing Snapshot file
' OutputPDFname is the name you select for the output PDF file
' ShowSaveFileDialog is a boolean param to specify whether or not to
display
' the standard windows File Dialog window to select an exisiting
Snapshot file
' CompressionLevel - Resolution in DPI(Dots per Inch) to apply to
embedded Images
' PasswordOpen - Users require to Open PDF
' PasswordOwner  - Users require to modify PDF
' PasswordRestrictions - Restrictions for viewing/editing/printing PDF
- See modReportToPDF for comments
' PDFNoFontEmbedding - Do not Embed fonts in PDF. Set to 1 to stop the
' default process of embedding all fonts in the output PDF. If you are
' using ONLY - any of the standard Windows fonts
' using ONLY - any of the standard 14 Fonts natively supported by the
PDF spec
'The 14 Standard Fonts
'All version of Adobe's Acrobat support 14 standard fonts. These fonts
are always available
'independent whether they are embedded or not.
'Family name PostScript name Style
'Courier Courier fsNone
'Courier Courier-Bold fsBold
'Courier Courier-Oblique fsItalic
'Courier Courier-BoldOblique fsBold + fsItalic
'Helvetica Helvetica fsNone
'Helvetica Helvetica-Bold fsBold
'Helvetica Helvetica-Oblique fsItalic
'Helvetica Helvetica-BoldOblique fsBold + fsItalic
'Times Times-Roman fsNone
'Times Times-Bold fsBold
'Times Times-Italic fsItalic
'Times Times-BoldItalic fsBold + fsItalic
'Symbol Symbol fsNone, other styles are emulated only
'ZapfDingbats ZapfDingbats fsNone, other styles are emulated only

' PDFUnicodeFlags controls how each metafile text record is
interpreted in terms
' of Unicode and BiDi language. See modDocumentor for details.
'
' You must pass either RptName or SnapshotName or set the
ShowSaveFileDialog param to TRUE.
' Any file names you pass to this function must include the full path.
If you only include the
' filename for the output PDF then your document will be saved to your
My Documents folder.


Dim blRet As Boolean
' Call our convert function
  Gina Whipp replied to Erick C
02-Feb-10 02:44 PM
Erick,

Step 1 copy the module into your database and then type here the name of
your report.  Also make sure you have a default printer assigned to windows.

--
Gina Whipp
2010 Microsoft MVP (Access)

II

http://www.regina-whipp.com/index_files/TipList.htm

Hi Gnia -
I apologize for the delay in my response, busy time for me at work.
I cannot seem to get anything going with this ReportToPDF.  I do not
know what I am doing, or not doing.  I have no idea how to integrate
the code into my current database.  I am just plain lost and becoming
frustrated, sadly.
I have copied the database and the two DLL files into the same folder
in My Documents along with my created database that I am testing.  I
just do not know what I am doing wrong, or how I am supposed to use
this ReportToPDF database.
If I just open the ReportToPDF database and try to use the form and
press the "Click Here to Save this Report as a PDF document" button I
get an error saying SnapshotToPDF: 2213 - There was a problem
retrieving printer information for this object.  The object may have
been sent to a printer that is unavailable.
I cannot seem to figure out what printer this report is pointing at.
My default network printer is set up correctly.
I also imported all of the modules into my own database, then copied
the event procedure code attached to the "Click Here" button from
above.
I tried to modify a few things to get it to work, but nothing doing.
If I try to use the button, I get a Run time error '2465':  Microsoft
Office Access cannot find the field "I" referred to in your expression.
Here is the code I tried to use:

Private Sub cmdReportToPDF_Click()
' Save the Report as a PDF document.
' The selected report is first exported to Snapshot format.
' The Snapshot file is then broken out into its
' component Enhanced Metafiles(EMF), one for each page of the report.
' Finally, the EMF's are converted to PDF pages within the master
' PDF document.

' The function call is:
'Public Function ConvertReportToPDF( _
'Optional RptName As String = "", _
'Optional SnapshotName As String = "", _
'Optional OutputPDFname As String = "", _
'Optional ShowSaveFileDialog As Boolean = False, _
'Optional StartPDFViewer As Boolean = True, _
'Optional CompressionLevel As Long = 150, _
'Optional PasswordOpen As String = "", _
'Optional PasswordOwner As String = "", _
'Optional PasswordRestrictions As Long = 0, _
'Optional PDFNoFontEmbedding as Long = 0, _
'Optional PDFUnicodeFlags As Long = 0 _
') As Boolean

' RptName is the name of a report contained within this MDB
' SnapshotName is the name of an existing Snapshot file
' OutputPDFname is the name you select for the output PDF file
' ShowSaveFileDialog is a boolean param to specify whether or not to
display
' the standard windows File Dialog window to select an exisiting
Snapshot file
' CompressionLevel - Resolution in DPI(Dots per Inch) to apply to
embedded Images
' PasswordOpen - Users require to Open PDF
' PasswordOwner  - Users require to modify PDF
' PasswordRestrictions - Restrictions for viewing/editing/printing PDF
- See modReportToPDF for comments
' PDFNoFontEmbedding - Do not Embed fonts in PDF. Set to 1 to stop the
' default process of embedding all fonts in the output PDF. If you are
' using ONLY - any of the standard Windows fonts
' using ONLY - any of the standard 14 Fonts natively supported by the
PDF spec
'The 14 Standard Fonts
'All version of Adobe's Acrobat support 14 standard fonts. These fonts
are always available
'independent whether they are embedded or not.
'Family name PostScript name Style
'Courier Courier fsNone
'Courier Courier-Bold fsBold
'Courier Courier-Oblique fsItalic
'Courier Courier-BoldOblique fsBold + fsItalic
'Helvetica Helvetica fsNone
'Helvetica Helvetica-Bold fsBold
'Helvetica Helvetica-Oblique fsItalic
'Helvetica Helvetica-BoldOblique fsBold + fsItalic
'Times Times-Roman fsNone
'Times Times-Bold fsBold
'Times Times-Italic fsItalic
'Times Times-BoldItalic fsBold + fsItalic
'Symbol Symbol fsNone, other styles are emulated only
  Erick C replied to Gina Whipp
02-Feb-10 08:43 PM
Hi Gina -
I have the module in my database.  I have double checked that my
defauly printer is working, everything is printing out of the database
OK.  Double checked to make sure it was not set up to the Adobe PDF
writer.
My report is "Sweeps_Report_For_Email"


dows.
s
  Gina Whipp replied to Erick C
02-Feb-10 03:16 PM
Erick,

Then put this line behind a button

DoCmd.OpenReport "Sweeps_Report_For_Email", acViewPreview
Call ConvertReportToPDF("Sweeps_Report_For_Email", , "c:\MyTestFile.pdf",
False)

and let me know what the results are.  Once we get this working I will
incorporate into other peice of code.

--
Gina Whipp
2010 Microsoft MVP (Access)

II

http://www.regina-whipp.com/index_files/TipList.htm

Hi Gina -
I have the module in my database.  I have double checked that my
defauly printer is working, everything is printing out of the database
OK.  Double checked to make sure it was not set up to the Adobe PDF
writer.
My report is "Sweeps_Report_For_Email"
  Erick C replied to Gina Whipp
02-Feb-10 08:43 PM
OK, the button opened up the report in preview view in access and
created a pdf file in my test folder (I modified the path in your
code) named MyTestFile.pdf, and the adobe viewer opened up.



s
f
ors
  Gina Whipp replied to Erick C
02-Feb-10 04:30 PM
Erick,

Okay, one more thing... the combo box that has your eMail addresses in it...

--
Gina Whipp
2010 Microsoft MVP (Access)

II

http://www.regina-whipp.com/index_files/TipList.htm

OK, the button opened up the report in preview view in access and
created a pdf file in my test folder (I modified the path in your
code) named MyTestFile.pdf, and the adobe viewer opened up.
  Erick C replied to Gina Whipp
02-Feb-10 08:43 PM
Gina -
The email addresses are not actually part of a combo box on my form, I
just have them all in a Customers_To_Email table.  The field is "Email
Address" in the table.
I need to somehow set up a loop with the code so an individual report
is created for each customer in the table.  The test PDF that was
created has all customers in it, which would not be too cool at all.
I also have a working code for emailing out of Lotus Notes, though I
do not know how to integrate it into the PDF code, but maybe it can
help.

Dim s As Object
Dim db As Object
Dim doc As Object
Dim rtItem As Object
Dim Server As String, Database As String
Dim strError As String
DoCmd.OutputTo acOutputReport, [Sweep_Report_For_Email], _
acFormatPDF, strTemp, strPathFile
'startup Lotus notes and get object handle
Set s =3D CreateObject("Notes.notesSession")
Server =3D s.GETENVIRONMENTSTRING("MailServer", True)
Database =3D s.GETENVIRONMENTSTRING("MailFile", True)
Set db =3D s.GetDatabase(Server, Database)

On Error GoTo ErrorLogon
'see if user is logged on
Set doc =3D db.CreateDocument
On Error GoTo 0

doc.Form =3D "Memo"
doc.importance =3D "1" '(Where 1=3DUrgent, 2=3D Normal, 3=3D FYI)

'Send an e-mail to
doc.sendTO =3D "email address goes here"
doc.RETURNRECEIPT =3D "1"
doc.Subject =3D "Test Email"


Set rtItem =3D doc.CreateRichTextItem("Body")
Call rtItem.AppendText("Test Email")
Call rtItem.AddNewLine(2)
Call rtItem.AppendText("Dear sir or madam")
Call rtItem.AddNewLine(1)
Call rtItem.AppendText("This is a test email for the Treasury
Department.  If you have received this in error, please disregard and
delete. ")
Call rtItem.AddNewLine(2)

Call rtItem.EMBEDOBJECT(1454, "", "G:\treas\Erick\Sweep Test Docs
\rates.xls")
doc.SaveMessageOnSend =3D True
doc.PostedDate =3D Now() 'Gets the mail to appear in the sent items
folder
Call doc.Send(False)

Set doc =3D Nothing
Set db =3D Nothing
Set s =3D Nothing
Set rtItem =3D Nothing

ErrorLogon:
If Err.Number =3D 7063 Then
MsgBox " You must first logon to Lotus Notes"
Set doc =3D Nothing
Set db =3D Nothing
Set s =3D Nothing
Set rtItem =3D Nothing
End If

Refresh
MsgBox " Your email has been sent"


...
s
  Gina Whipp replied to Erick C
02-Feb-10 07:13 PM
Erick,

First, pardon the delay.. emergency... Eating dinner will look at this when
I finish.

--
Gina Whipp
2010 Microsoft MVP (Access)

II

http://www.regina-whipp.com/index_files/TipList.htm

Gina -
The email addresses are not actually part of a combo box on my form, I
just have them all in a Customers_To_Email table.  The field is "Email
Address" in the table.
I need to somehow set up a loop with the code so an individual report
is created for each customer in the table.  The test PDF that was
created has all customers in it, which would not be too cool at all.
I also have a working code for emailing out of Lotus Notes, though I
do not know how to integrate it into the PDF code, but maybe it can
help.

Dim s As Object
Dim db As Object
Dim doc As Object
Dim rtItem As Object
Dim Server As String, Database As String
Dim strError As String
DoCmd.OutputTo acOutputReport, [Sweep_Report_For_Email], _
acFormatPDF, strTemp, strPathFile
'startup Lotus notes and get object handle
Set s = CreateObject("Notes.notesSession")
Server = s.GETENVIRONMENTSTRING("MailServer", True)
Database = s.GETENVIRONMENTSTRING("MailFile", True)
Set db = s.GetDatabase(Server, Database)

On Error GoTo ErrorLogon
'see if user is logged on
Set doc = db.CreateDocument
On Error GoTo 0

doc.Form = "Memo"
doc.importance = "1" '(Where 1=Urgent, 2= Normal, 3= FYI)

'Send an e-mail to
doc.sendTO = "email address goes here"
doc.RETURNRECEIPT = "1"
doc.Subject = "Test Email"


Set rtItem = doc.CreateRichTextItem("Body")
Call rtItem.AppendText("Test Email")
Call rtItem.AddNewLine(2)
Call rtItem.AppendText("Dear sir or madam")
Call rtItem.AddNewLine(1)
Call rtItem.AppendText("This is a test email for the Treasury
Department.  If you have received this in error, please disregard and
delete. ")
Call rtItem.AddNewLine(2)

Call rtItem.EMBEDOBJECT(1454, "", "G:\treas\Erick\Sweep Test Docs
\rates.xls")
doc.SaveMessageOnSend = True
doc.PostedDate = Now() 'Gets the mail to appear in the sent items
folder
Call doc.Send(False)

Set doc = Nothing
Set db = Nothing
Set s = Nothing
Set rtItem = Nothing

ErrorLogon:
If Err.Number = 7063 Then
MsgBox " You must first logon to Lotus Notes"
Set doc = Nothing
Set db = Nothing
Set s = Nothing
Set rtItem = Nothing
End If

Refresh
MsgBox " Your email has been sent"
  Gina Whipp replied to Erick C
02-Feb-10 09:37 PM
Erick,

First, the report has to drop out to individual files, one way or the
other...  So whether you use a combo box or a list box does not matter.  But
it must loop thru and attach a number or something on to the end of each
file so it knows the reports are seperate entities.  Might be better to pick
to pick the CustomerID as the report name so when eMailing the eMail knows
which report to grab.  (I can modify to include CustomerID.)

'Posted by ADezii 5.23.2009 on bytes.com
'Modified by Gina Whipp 11.4.2009 to OutputTo Multiple Files
'Tested in Access 2003

Dim intCounter As Integer
Dim cboCode As ComboBox

Set cboCode = Me![YourComboBox]

For intCounter = 0 To Combo0.ListCount - 1
DoCmd.OpenReport "Sweeps_Report_For_Email", acViewPreview, ,
DoEvents
Call ConvertReportToPDF("Report1", ,
& ".pdf", False, False)
DoCmd.Close acReport, "Sweeps_Report_For_Email"
Next

The code you supplied below appears to go to one eMail address at a time...
Is this true?  I do not have Lotus Notes so no way to test.


--
Gina Whipp
2010 Microsoft MVP (Access)

II

http://www.regina-whipp.com/index_files/TipList.htm

Gina -
The email addresses are not actually part of a combo box on my form, I
just have them all in a Customers_To_Email table.  The field is "Email
Address" in the table.
I need to somehow set up a loop with the code so an individual report
is created for each customer in the table.  The test PDF that was
created has all customers in it, which would not be too cool at all.
I also have a working code for emailing out of Lotus Notes, though I
do not know how to integrate it into the PDF code, but maybe it can
help.

Dim s As Object
Dim db As Object
Dim doc As Object
Dim rtItem As Object
Dim Server As String, Database As String
Dim strError As String
'startup Lotus notes and get object handle
Set s = CreateObject("Notes.notesSession")
Server = s.GETENVIRONMENTSTRING("MailServer", True)
Database = s.GETENVIRONMENTSTRING("MailFile", True)
Set db = s.GetDatabase(Server, Database)

On Error GoTo ErrorLogon
'see if user is logged on
Set doc = db.CreateDocument
On Error GoTo 0

doc.Form = "Memo"
doc.importance = "1" '(Where 1=Urgent, 2= Normal, 3= FYI)

'Send an e-mail to
doc.sendTO = "email address goes here"
doc.RETURNRECEIPT = "1"
doc.Subject = "Test Email"


Set rtItem = doc.CreateRichTextItem("Body")
Call rtItem.AppendText("Test Email")
Call rtItem.AddNewLine(2)
Call rtItem.AppendText("Dear sir or madam")
Call rtItem.AddNewLine(1)
Call rtItem.AppendText("This is a test email for the Treasury
Department.  If you have received this in error, please disregard and
delete. ")
Call rtItem.AddNewLine(2)

Call rtItem.EMBEDOBJECT(1454, "", "G:\treas\Erick\Sweep Test Docs
\rates.xls")
doc.SaveMessageOnSend = True
doc.PostedDate = Now() 'Gets the mail to appear in the sent items
folder
Call doc.Send(False)

Set doc = Nothing
Set db = Nothing
Set s = Nothing
  Erick C replied to Gina Whipp
03-Feb-10 03:38 AM
Gina -
I am not the biggest fan of Lotus Notes myself, this would be so much
easier if I was using Outlook.  Regarding your email code question,
yes you are correct.  The code as it is written emails only one
address at a time.  I had guessed that it would be better and easier
to integrate into another code.   I also added a list box to my form
that pulls in the customer ID (AcctNum), customer name, and email
address.
I thought that the same list box could be used to pull an email
address right after it was used to create and name the pdf.  So, the
identifying portion of the name of the file would come from the
customer ID column in the list box, then the email address from the
email section of the list box.  SO basically right after a pdf is made
it is emailed and then it moves on to the next customer ID in the list
box.  Does my weird thought process make any sense at all, or was I
way off?

OK, I have changed the code attached to the button, but I have
received an error saying Compile error: cannot find project or
library.  The debugger highlights Format at the beginning of "Format
(intCounter,"000")"
Here is what my code looks like, did I add something that I was not
supposed to?

Dim intCounter As Integer
Dim cboCode As ComboBox


Set cboCode =3D Me![CustomerListBox]


For intCounter =3D 0 To CustomerListBox.ListCount - 1
DoCmd.OpenReport "Sweeps_Report_For_Email", acViewPreview, ,
DoEvents
Call ConvertReportToPDF("Report1", , "C:\Users\Erick\Documents\Test
\Sweeps_Report_For_Email" & Format(intCounter, "000") & ".pdf", False,
False)
DoCmd.Close acReport, "Sweeps_Report_For_Email"
Next




=A0But
pick
s
0")
..
s
  Gina Whipp replied to Erick C
03-Feb-10 09:46 AM
Erick,

Is it looking at a text field or a numeric field?

--
Gina Whipp
2010 Microsoft MVP (Access)

II

http://www.regina-whipp.com/index_files/TipList.htm

Gina -
I am not the biggest fan of Lotus Notes myself, this would be so much
easier if I was using Outlook.  Regarding your email code question,
yes you are correct.  The code as it is written emails only one
address at a time.  I had guessed that it would be better and easier
to integrate into another code.   I also added a list box to my form
that pulls in the customer ID (AcctNum), customer name, and email
address.
I thought that the same list box could be used to pull an email
address right after it was used to create and name the pdf.  So, the
identifying portion of the name of the file would come from the
customer ID column in the list box, then the email address from the
email section of the list box.  SO basically right after a pdf is made
it is emailed and then it moves on to the next customer ID in the list
box.  Does my weird thought process make any sense at all, or was I
way off?

OK, I have changed the code attached to the button, but I have
received an error saying Compile error: cannot find project or
library.  The debugger highlights Format at the beginning of "Format
(intCounter,"000")"
Here is what my code looks like, did I add something that I was not
supposed to?

Dim intCounter As Integer
Dim cboCode As ComboBox


Set cboCode = Me![CustomerListBox]


For intCounter = 0 To CustomerListBox.ListCount - 1
DoCmd.OpenReport "Sweeps_Report_For_Email", acViewPreview, ,
DoEvents
Call ConvertReportToPDF("Report1", , "C:\Users\Erick\Documents\Test
\Sweeps_Report_For_Email" & Format(intCounter, "000") & ".pdf", False,
False)
DoCmd.Close acReport, "Sweeps_Report_For_Email"
Next
  Erick C replied to Gina Whipp
03-Feb-10 10:34 AM
Good morning Gina!
AcctNum is a text field.


s
ut
h
ows
  Erick C replied to Erick C
03-Feb-10 05:37 PM
Gina -
Sorry, I had an error in my code.  I fixed it and the code now creates
individual pdf files for each customer.  The file is named


ors
e
But
ach
o
knows
  Gina Whipp replied to Erick C
03-Feb-10 01:06 PM
Erick,

Okay... now the we need to find a way to identify the report for each
Customer...  I suggested using the CustomerID is that an option for you?

--
Gina Whipp
2010 Microsoft MVP (Access)

II

http://www.regina-whipp.com/index_files/TipList.htm

Gina -
Sorry, I had an error in my code.  I fixed it and the code now creates
individual pdf files for each customer.  The file is named
  Erick C replied to Gina Whipp
03-Feb-10 05:38 PM
Absolutely, Customer ID (AcctNum) can be sued to identify the reports.


?
s
..
t
,
  Erick C replied to Erick C
03-Feb-10 05:38 PM
Gina -
OK, I have in my combo box a field for [AcctNum] and [Email Address].
The AcctNum field is a unique identifier for each customer account,
there are absolutely no duplicate records ever.  It is a text field
since the number is not solely numeric.
Let me know if I need to put the info somewhere other than the combo
box that is already being used.


ou?
ors
.
s
m...
ch
de
ist
  Gina Whipp replied to Erick C
03-Feb-10 02:37 PM
Erick,

Then adjust the line to say...

Call ConvertReportToPDF("Report1", , "C:\Users\Erick\Documents\Test\" &
Me.AccNum & "-Sweeps_Report_For_Email" & Format(intCounter, "000") & ".pdf",
False, False)

I added the dash so the code can gleam the AccNum which we can tell it
before the dash...

Now, I have some code to loops thru Lotus Notes and send a PDF report, only
as I do not have Lotus Notes I have no way to test or even play to modify...

'***Start of Code (looks to be attached to a command button)
Private Sub cmdSendMail_Click()

Dim user As String, server As String, mailfile As String
Dim doc As Object, rtobject As Object
Dim session As Object, db As Object
Dim item As Object, rtitem As Variant
Dim Picture As Object

'Arrays to hold a list of Email Recipients and a list of
'pdf files to be attached to the email
Dim strSendTo() As String
Dim strPDFList() As String
Dim strBodyText As String
Dim strSubject As String
Dim i As Integer

'Retrieves pdf file locations from an Access Database
Set mrstAccess = mconAccess.Execute("SELECT To FROM Email")

'Adds all recipients to be emailed to the email
i = 1
Do While Not mrstAccess.EOF
ReDim Preserve strSendTo(i)
strSendTo(i) = mrstAccess![To]
mrstAccess.MoveNext
i = i + 1
Loop

strSubject = txtSubject.Text
strBodyText = txtBody.Text

'Creates a Notessession Object and provides mail details
Set session = CreateObject("notes.notessession")
user = session.UserName
server = session.GETENVIRONMENTSTRING("MailServer", True)
mailfile = session.GETENVIRONMENTSTRING("MailFile", True)
Set db = session.GETDATABASE(server, mailfile)
Set doc = db.CREATEDOCUMENT()
doc.Form = "Memo"
doc.sendto = strSendTo()
doc.Subject = strSubject
Set rtitem = doc.CreateRichTextItem("body")
Call rtitem.APPENDTEXT(strBodyText)
Call rtitem.ADDNEWLINE(2)

'Retrieves pdf file locations from an Access Database
Set mrstAccess = mconAccess.Execute("SELECT PDF_Name FROM PDFs")

'Attaches all pdf files specified to the email
i = 1
Do While Not mrstAccess.EOF
ReDim Preserve strPDFList(i)
strPDFList(i) = mrstAccess![PDF_Name]
Set item = rtitem.EMBEDOBJECT(1454, "", strPDFList(i))
mrstAccess.MoveNext
i = i + 1
Loop

'Send the mail
Call doc.Send(False)
Set doc = Nothing

End Sub
'***End of Code

There is also more information here..
http://www.bigresource.com/VB-Visual-Basic-to-send-Lotus-Notes-Email-039-s-to-multiple-recipients--qQPm7FnXjQ.html#

Do you think you can modify the above?

--
Gina Whipp
2010 Microsoft MVP (Access)

II

http://www.regina-whipp.com/index_files/TipList.htm

Absolutely, Customer ID (AcctNum) can be sued to identify the reports.
  Gina Whipp replied to Erick C
03-Feb-10 03:33 PM
Erick,

Did my reply not show up?

--
Gina Whipp
2010 Microsoft MVP (Access)

II

http://www.regina-whipp.com/index_files/TipList.htm

Gina -
OK, I have in my combo box a field for [AcctNum] and [Email Address].
The AcctNum field is a unique identifier for each customer account,
there are absolutely no duplicate records ever.  It is a text field
since the number is not solely numeric.
Let me know if I need to put the info somewhere other than the combo
box that is already being used.
  Erick C replied to Gina Whipp
03-Feb-10 05:38 PM
Hi Gina -
I have changed the Call line, but I received an error saying "Complie
Error: Method or Data Member Not Found " and the debugger highlighted
the ".AcctNum" part of Me.AcctNum.

As far as the email portion goes, I will do my best to try and get it
going.  I have run into a snag already with the  'Retrieves pdf file
locations from an Access Database
What goes into the To and Email Portion?
If I try to run it errors and highlights the above line, the error
says Error 424, Object Required


f",
ly
..
)
  Gina Whipp replied to Erick C
03-Feb-10 03:50 PM
Erick,

Sorry Me.NameOfAccNumField on your form.

--
Gina Whipp
2010 Microsoft MVP (Access)

II

http://www.regina-whipp.com/index_files/TipList.htm

Hi Gina -
I have changed the Call line, but I received an error saying "Complie
Error: Method or Data Member Not Found " and the debugger highlighted
the ".AcctNum" part of Me.AcctNum.

As far as the email portion goes, I will do my best to try and get it
going.  I have run into a snag already with the  'Retrieves pdf file
locations from an Access Database
What goes into the To and Email Portion?
If I try to run it errors and highlights the above line, the error
says Error 424, Object Required
  Erick C replied to Gina Whipp
03-Feb-10 05:38 PM
Hi Gina -
I am so sorry that I keep messing this thing up.  I know you are tired
of sending me responses.  Believe me, I am tired of looking at this
thing too.  This will be my last access database for quite a while!
I get an error when I enter the name of the field after Me.  So if I
put in Me.AcctNum I get an error saying Method or data member not
found.  If I enter Me.[AcctNum] I get an error #2465 saying Microsoft
Access cannot find the field "I" referred to in your expression.


s
Execute("SELECT To FROM Email")
  Erick C replied to Erick C
03-Feb-10 05:38 PM
Oh, and if I put Me.[Combo24]![AcctNum] I get a type mismatch error.


ors
.
e
s.Execute("SELECT To FROM Email")
&
t
,
  Gina Whipp replied to Erick C
03-Feb-10 04:39 PM
Erick,

No worries... we will get it... what is the name of the field that has
AccNum cause it sounds like you should put Me.Combo24

--
Gina Whipp
2010 Microsoft MVP (Access)

II

http://www.regina-whipp.com/index_files/TipList.htm

Oh, and if I put Me.[Combo24]![AcctNum] I get a type mismatch error.
  Erick C replied to Gina Whipp
03-Feb-10 05:38 PM
I also tried Me.Combo24, but it only gives a name if I actually select
something in the combo box.  So if I make no selection at all I get
nothing in the name.  And If I make a selection in the combo box then
every pdf that is created comes up with the same name.


s
...
\"
&
it
rt,
  Erick C replied to Erick C
03-Feb-10 05:38 PM
Or I should clarify, I do not get anything before the -
Sweep_To_Email.pdf.  So where we would expect to see the AcctNum,
there is nothing if nothing is selected in the combo box.  But the pdf
still gets created, just missing the beginning part of the name.


ors
.
om...
ie
ed
it
st\"
) &
  Gina Whipp replied to Erick C
03-Feb-10 05:34 PM
Erick,

AccNum-Sweep_To_Email001.pdf

Please copy/paste the code you are using here... maybe I missed something!

--
Gina Whipp
2010 Microsoft MVP (Access)

II

http://www.regina-whipp.com/index_files/TipList.htm

Or I should clarify, I do not get anything before the -
Sweep_To_Email.pdf.  So where we would expect to see the AcctNum,
there is nothing if nothing is selected in the combo box.  But the pdf
still gets created, just missing the beginning part of the name.
  Erick C replied to Gina Whipp
04-Feb-10 02:40 PM
Hi Gina -
Here is the code that I currently have.  This code exports files with
names like "-Sweep_To_Email000.pdf"

Dim intCounter As Integer
Dim cboCode As ComboBox


Set cboCode =3D Me![Combo24]


For intCounter =3D 0 To Combo24.ListCount - 1
DoCmd.OpenReport "Sweep_Report_For_Email", acViewPreview, ,
DoEvents
Call ConvertReportToPDF("Sweep_Report_For_Email", , "C:\Documents
and Settings\ecrump\My Documents\Access Test\Test Files\" & Me.Combo24
& "-Sweeps_Report_For_Email" & Format(intCounter, "000") & ".pdf",
False, False)
DoCmd.Close acReport, "Sweep_Report_For_Email"
Next




!
s
s
...
ed
t
  Gina Whipp replied to Erick C
04-Feb-10 01:15 PM
Erick,

My fault, it is not cycling the combo box to get CustomerID.  Let me think on
this...

--
Gina Whipp
2010 Microsoft MVP (Access)

II

http://www.regina-whipp.com/index_files/TipList.htm

Hi Gina -
Here is the code that I currently have.  This code exports files with
names like "-Sweep_To_Email000.pdf"

Dim intCounter As Integer
Dim cboCode As ComboBox


Set cboCode = Me![Combo24]


For intCounter = 0 To Combo24.ListCount - 1
DoCmd.OpenReport "Sweep_Report_For_Email", acViewPreview, ,
DoEvents
Call ConvertReportToPDF("Sweep_Report_For_Email", , "C:\Documents
and Settings\ecrump\My Documents\Access Test\Test Files\" & Me.Combo24
& "-Sweeps_Report_For_Email" & Format(intCounter, "000") & ".pdf",
False, False)
DoCmd.Close acReport, "Sweep_Report_For_Email"
Next
  Erick C replied to Gina Whipp
04-Feb-10 09:30 PM
Gina -
No problem.  I am just happy that I was not going crazy, or I had
entered something incorrectly.


nk on
s
ng!
ors
t
has
  Gina Whipp replied to Erick C
04-Feb-10 05:13 PM
Erick,

I am going to have to admit this one has me stumped...  Anything I do to
loop thru the data to extract the CustomerID still only grabs the first
CustomerID.  I am trying to find a way to identify the report so you know
which eMail to attach it to without opening each report and checking it.
Not giving up just yet...  just not sure to get it to do what I want it to
do...

--
Gina Whipp
2010 Microsoft MVP (Access)

II

http://www.regina-whipp.com/index_files/TipList.htm

Gina -
No problem.  I am just happy that I was not going crazy, or I had
entered something incorrectly.
  Erick C replied to Gina Whipp
04-Feb-10 09:30 PM
Hi Gina -
I am searching away on my side to see if I can find anything that may
help out.  I will have to check out a few more websites once I get
home.
I do have a code that I use in another database, though the purpose is
different.  Maybe some of the code might give you an idea.
The code creates dummy queries for each individual managerID and then
exports a xls file for each managerID.  I cannot tell you everything
that the code is doing, but I know that it looks at a managerID table
in the database and adds the managerID field to the name of the
exported file and moves to the next one.  Just thought it may possibly
help, or not.

Dim dbs As DAO.Database
Dim rstMgr As DAO.Recordset, rstMgr1 As DAO.Recordset
Dim strSQL As String, strTemp As String, strMgr As String
Dim strPathFile As String, strFile As String, strPath As String
Dim strTable As String, strBrowseMsg As String
Dim blnHasFieldNames As Boolean
strBrowseMsg =3D "Select the folder where the detail files will be
created:"
strPath =3D BrowseFolder(strBrowseMsg)
If strPath =3D "" Then
MsgBox "No folder was selected.", vbOK, "No Selection"
Exit Sub
End If
Const strQName As String =3D "zExportQuery"
Set dbs =3D CurrentDb
' Create temporary query that will be used for exporting data;
' we give it a dummy SQL statement initially (this name will
' be changed by the code to conform to each manager's identification)
strTemp =3D dbs.TableDefs(0).Name
strSQL =3D "SELECT * FROM [" & strTemp & "] WHERE 1=3D0;"
Set qdf =3D dbs.CreateQueryDef(strQName, strSQL)
qdf.Close
strTemp =3D strQName
' *** code to set strSQL needs to be changed to conform to your
' *** database design -- ManagerID and EmployeesTable need to
' *** be changed to your table and field names
' Get list of ManagerID values -- note: replace my generic table and
Field names
' with the real names of the EmployeesTable table and the ManagerID
Field
strSQL =3D "SELECT DISTINCT Subinventory FROM [Subinv Subtotal By
Transaction Type];"
Set rstMgr =3D dbs.OpenRecordset(strSQL, dbOpenDynaset, dbReadOnly)
' Now loop through list of ManagerID values and create a query foreach
ManagerID
' so that the data can be exported -- the code assumes that the actual
names
' of the managers are in a lookup table -- again, replace generic
names with
' real names of tables and fields
If rstMgr.EOF =3D False And rstMgr.BOF =3D False Then
rstMgr.MoveFirst
Do While rstMgr.EOF =3D False
' *** code to set strMgr needs to be changed to conform to your
' *** database design -- ManagerNameField, ManagersTable, and
' *** ManagerID need to be changed to your table and field names
' *** be changed to your table and field names
strMgr =3D DLookup("Subinventory", "Stores for Export", _
' *** code to set strSQL needs to be changed to conform to your
' *** database design -- ManagerID and EmployeesTable need to
' *** be changed to your table and field names
strSQL =3D "SELECT * FROM [Subinv Subtotal By Transaction
Type] WHERE " & _
Set qdf =3D dbs.QueryDefs(strTemp)
qdf.Name =3D "q_" & strMgr
strTemp =3D qdf.Name
qdf.SQL =3D strSQL
qdf.Close
Set qdf =3D Nothing
strFile =3D Format$(Date, "Medium Date") & " " & strMgr &
strPathFile =3D strPath & "\" & strFile
DoCmd.TransferSpreadsheet acExport,
acSpreadsheetTypeExcel9, strTemp, strPathFile
rstMgr.MoveNext
Loop



o
ow
to
  Gina Whipp replied to Erick C
04-Feb-10 05:41 PM
Erick,

Thanks, it might give me an idea!

--
Gina Whipp
2010 Microsoft MVP (Access)

II

http://www.regina-whipp.com/index_files/TipList.htm

Hi Gina -
I am searching away on my side to see if I can find anything that may
help out.  I will have to check out a few more websites once I get
home.
I do have a code that I use in another database, though the purpose is
different.  Maybe some of the code might give you an idea.
The code creates dummy queries for each individual managerID and then
exports a xls file for each managerID.  I cannot tell you everything
that the code is doing, but I know that it looks at a managerID table
in the database and adds the managerID field to the name of the
exported file and moves to the next one.  Just thought it may possibly
help, or not.

Dim dbs As DAO.Database
Dim rstMgr As DAO.Recordset, rstMgr1 As DAO.Recordset
Dim strSQL As String, strTemp As String, strMgr As String
Dim strPathFile As String, strFile As String, strPath As String
Dim strTable As String, strBrowseMsg As String
Dim blnHasFieldNames As Boolean
strBrowseMsg = "Select the folder where the detail files will be
created:"
strPath = BrowseFolder(strBrowseMsg)
If strPath = "" Then
MsgBox "No folder was selected.", vbOK, "No Selection"
Exit Sub
End If
Const strQName As String = "zExportQuery"
Set dbs = CurrentDb
' Create temporary query that will be used for exporting data;
' we give it a dummy SQL statement initially (this name will
' be changed by the code to conform to each manager's identification)
strTemp = dbs.TableDefs(0).Name
strSQL = "SELECT * FROM [" & strTemp & "] WHERE 1=0;"
Set qdf = dbs.CreateQueryDef(strQName, strSQL)
qdf.Close
strTemp = strQName
' *** code to set strSQL needs to be changed to conform to your
' *** database design -- ManagerID and EmployeesTable need to
' *** be changed to your table and field names
' Get list of ManagerID values -- note: replace my generic table and
Field names
' with the real names of the EmployeesTable table and the ManagerID
Field
strSQL = "SELECT DISTINCT Subinventory FROM [Subinv Subtotal By
Transaction Type];"
Set rstMgr = dbs.OpenRecordset(strSQL, dbOpenDynaset, dbReadOnly)
' Now loop through list of ManagerID values and create a query foreach
ManagerID
' so that the data can be exported -- the code assumes that the actual
names
' of the managers are in a lookup table -- again, replace generic
names with
' real names of tables and fields
If rstMgr.EOF = False And rstMgr.BOF = False Then
rstMgr.MoveFirst
Do While rstMgr.EOF = False
' *** code to set strMgr needs to be changed to conform to your
' *** database design -- ManagerNameField, ManagersTable, and
' *** ManagerID need to be changed to your table and field names
' *** be changed to your table and field names
strMgr = DLookup("Subinventory", "Stores for Export", _
' *** code to set strSQL needs to be changed to conform to your
' *** database design -- ManagerID and EmployeesTable need to
' *** be changed to your table and field names
strSQL = "SELECT * FROM [Subinv Subtotal By Transaction
Type] WHERE " & _
Set qdf = dbs.QueryDefs(strTemp)
qdf.Name = "q_" & strMgr
strTemp = qdf.Name
qdf.SQL = strSQL
qdf.Close
Set qdf = Nothing
strFile = Format$(Date, "Medium Date") & " " & strMgr &
strPathFile = strPath & "\" & strFile
DoCmd.TransferSpreadsheet acExport,
acSpreadsheetTypeExcel9, strTemp, strPathFile
rstMgr.MoveNext
Loop
  Erick C replied to Gina Whipp
05-Feb-10 04:25 AM
Hi Gina -
I have some more code for you.  I found something that is referencing
the same Lebans ConvertReportToPDF.  I thought it may help.  From the
description I believe it is supposed to loop through different
CustomerIDs:


Private Sub cmdBulkConvertIndividualCustReports_Click()

'Notes:--------------------------------------------------------------------=
-----------
'- You need to download this file from Lebans.com:
'(http://www.lebans.com/DownloadFiles/A2000SnapshotToPDFver785.zip
'... then copy the DLL's to your Windows/system32 folder,
'(Or to the same folder this database is in.)
'--------------------------------------------------------------------------=
-----------

On Error GoTo Err_cmdEmailIndividualCustReports_Click

'Declare Variables and Objects
Dim dbs                 As DAO.Database
Dim rst                 As DAO.Recordset
Dim strSQL              As String
Dim strCustID           As String
Dim strEmail            As String
Dim strReportName       As String
Dim blRet               As Boolean

'Set Variables and Objects
strSQL =3D "SELECT CustomerID,EmailAddress From tblCustomers"
Set dbs =3D CurrentDb()
Set rst =3D dbs.OpenRecordset(strSQL)
strReportName =3D "rptEmailCustReportCustomers"

rst.MoveFirst

'Turns off the screen
DoCmd.Echo False
Do While Not rst.EOF
strCustID =3D rst!CustomerID
strEmail =3D rst!EmailAddress
'If CustomerID is a number change to: "CustomerID=3D" &
strCustID
DoCmd.OpenReport strReportName, acViewPreview, ,

'This is the call to the Stephen Lebans code.
blRet =3D ConvertReportToPDF(strReportName,
vbNullString, "C:\YourFolder\" & strReportName & "_Cust_" & strCustID
& ".pdf", False, False, 150, "", "", 0, 0, 0)

DoCmd.Close acReport, strReportName

rst.MoveNext
Loop
DoCmd.Echo True
MsgBox "Done", vbInformation

'Recordset Cleanup Code
rst.Close
Set rst =3D Nothing
dbs.Close
Set dbs =3D Nothing

Exit_cmdEmailIndividualCustReports_Click:
'Avoids the endless loop
DoCmd.Echo True
On Error Resume Next
rst.Close
Set rst =3D Nothing
dbs.Close
Set dbs =3D Nothing
Exit Sub

Err_cmdEmailIndividualCustReports_Click:

MsgBox "There was an error executing the command." _
& vbCrLf & vbCrLf & "Error " & Err.Number & ": " _
& vbCrLf & vbCrLf & Error, vbExclamation

Resume Exit_cmdEmailIndividualCustReports_Click

End Sub


s
  Erick C replied to Erick C
05-Feb-10 12:25 PM
Gina -
I am happy to report that I have had a breakthrough!
I took the code that I sent you in the last post and messed around
with it for a while.  I finally got the code to work.  It creates an
individual PDF and adds the AcctNum to the name for each one.
Now I am going to start chipping away at the email part and see if I
can use some of the same stuff in this code for looping and finding
each customer's AcctNum and email address.
Thank you again for all of your patience and work.  I know it was a
chore just getting me to this point.

Here is what I ended up using:

'Declare Variables and Objects
Dim dbs                 As DAO.Database
Dim rst                 As DAO.Recordset
Dim strSQL              As String
Dim strAcctNum          As String
Dim strReportName       As String


'Set Variables and Objects
strSQL =3D "SELECT AcctNum From Customers_To_Email"
Set dbs =3D CurrentDb()
Set rst =3D dbs.OpenRecordset(strSQL)
strReportName =3D "Sweep_Report_For_Email"


rst.MoveFirst


'Turns off the screen
DoCmd.Echo True
Do While Not rst.EOF
strAcctNum =3D rst!AcctNum
'If CustomerID is a number change to: "CustomerID=3D"
&strCustID
DoCmd.OpenReport strReportName, acViewPreview, , "[BNY
Acct#]=3D" & "'" & strAcctNum & "'"


'This is the call to the Stephen Lebans code.
Call ConvertReportToPDF(strReportName, , "C:\Documents
and Settings\ecrump\My Documents\Access Test\Test Files\" & strAcctNum
& ".pdf", False, False)

DoCmd.Close acReport, strReportName

rst.MoveNext
Loop
DoCmd.Echo True
MsgBox "Done", vbInformation

'Recordset Cleanup Code
rst.Close
Set rst =3D Nothing
dbs.Close
Set dbs =3D Nothing

End Sub



--=AD-----------
--=AD-----------
  Gina Whipp replied to Erick C
05-Feb-10 06:17 PM
Erick,

Glad to hear that!  So sorry, I did not get back to you... had a Client
emergency!

Not a chore at all... and for someone who siad I do not know alot about VBA,
you did an excellent job!  I would also like to thank you for sharing your
solution as I am sure it will benefit someone else!

--
Gina Whipp
2010 Microsoft MVP (Access)

II

http://www.regina-whipp.com/index_files/TipList.htm

Gina -
I am happy to report that I have had a breakthrough!
I took the code that I sent you in the last post and messed around
with it for a while.  I finally got the code to work.  It creates an
individual PDF and adds the AcctNum to the name for each one.
Now I am going to start chipping away at the email part and see if I
can use some of the same stuff in this code for looping and finding
each customer's AcctNum and email address.
Thank you again for all of your patience and work.  I know it was a
chore just getting me to this point.

Here is what I ended up using:

'Declare Variables and Objects
Dim dbs                 As DAO.Database
Dim rst                 As DAO.Recordset
Dim strSQL              As String
Dim strAcctNum          As String
Dim strReportName       As String


'Set Variables and Objects
strSQL = "SELECT AcctNum From Customers_To_Email"
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset(strSQL)
strReportName = "Sweep_Report_For_Email"


rst.MoveFirst


'Turns off the screen
DoCmd.Echo True
Do While Not rst.EOF
strAcctNum = rst!AcctNum
'If CustomerID is a number change to: "CustomerID="
&strCustID
DoCmd.OpenReport strReportName, acViewPreview, , "[BNY
Acct#]=" & "'" & strAcctNum & "'"


'This is the call to the Stephen Lebans code.
Call ConvertReportToPDF(strReportName, , "C:\Documents
and Settings\ecrump\My Documents\Access Test\Test Files\" & strAcctNum
& ".pdf", False, False)

DoCmd.Close acReport, strReportName

rst.MoveNext
Loop
DoCmd.Echo True
MsgBox "Done", vbInformation

'Recordset Cleanup Code
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing

End Sub
  Ken Snell replied to Erick C
05-Feb-10 11:35 PM
Hey, I recognize this code! <grin>
--

Ken Snell
http://www.accessmvp.com/KDSnell/


Hi Gina -
I am searching away on my side to see if I can find anything that may
help out.  I will have to check out a few more websites once I get
home.
I do have a code that I use in another database, though the purpose is
different.  Maybe some of the code might give you an idea.
The code creates dummy queries for each individual managerID and then
exports a xls file for each managerID.  I cannot tell you everything
that the code is doing, but I know that it looks at a managerID table
in the database and adds the managerID field to the name of the
exported file and moves to the next one.  Just thought it may possibly
help, or not.

Dim dbs As DAO.Database
Dim rstMgr As DAO.Recordset, rstMgr1 As DAO.Recordset
Dim strSQL As String, strTemp As String, strMgr As String
Dim strPathFile As String, strFile As String, strPath As String
Dim strTable As String, strBrowseMsg As String
Dim blnHasFieldNames As Boolean
strBrowseMsg = "Select the folder where the detail files will be
created:"
strPath = BrowseFolder(strBrowseMsg)
If strPath = "" Then
MsgBox "No folder was selected.", vbOK, "No Selection"
Exit Sub
End If
Const strQName As String = "zExportQuery"
Set dbs = CurrentDb
' Create temporary query that will be used for exporting data;
' we give it a dummy SQL statement initially (this name will
' be changed by the code to conform to each manager's identification)
strTemp = dbs.TableDefs(0).Name
strSQL = "SELECT * FROM [" & strTemp & "] WHERE 1=0;"
Set qdf = dbs.CreateQueryDef(strQName, strSQL)
qdf.Close
strTemp = strQName
' *** code to set strSQL needs to be changed to conform to your
' *** database design -- ManagerID and EmployeesTable need to
' *** be changed to your table and field names
' Get list of ManagerID values -- note: replace my generic table and
Field names
' with the real names of the EmployeesTable table and the ManagerID
Field
strSQL = "SELECT DISTINCT Subinventory FROM [Subinv Subtotal By
Transaction Type];"
Set rstMgr = dbs.OpenRecordset(strSQL, dbOpenDynaset, dbReadOnly)
' Now loop through list of ManagerID values and create a query foreach
ManagerID
' so that the data can be exported -- the code assumes that the actual
names
' of the managers are in a lookup table -- again, replace generic
names with
' real names of tables and fields
If rstMgr.EOF = False And rstMgr.BOF = False Then
rstMgr.MoveFirst
Do While rstMgr.EOF = False
' *** code to set strMgr needs to be changed to conform to your
' *** database design -- ManagerNameField, ManagersTable, and
' *** ManagerID need to be changed to your table and field names
' *** be changed to your table and field names
strMgr = DLookup("Subinventory", "Stores for Export", _
' *** code to set strSQL needs to be changed to conform to your
' *** database design -- ManagerID and EmployeesTable need to
' *** be changed to your table and field names
strSQL = "SELECT * FROM [Subinv Subtotal By Transaction
Type] WHERE " & _
Set qdf = dbs.QueryDefs(strTemp)
qdf.Name = "q_" & strMgr
strTemp = qdf.Name
qdf.SQL = strSQL
qdf.Close
Set qdf = Nothing
strFile = Format$(Date, "Medium Date") & " " & strMgr &
strPathFile = strPath & "\" & strFile
DoCmd.TransferSpreadsheet acExport,
acSpreadsheetTypeExcel9, strTemp, strPathFile
rstMgr.MoveNext
Loop
  Gina Whipp replied to Ken Snell
06-Feb-10 12:00 AM
Ken,

He actually gave you credit in the first post of this thread!

--
Gina Whipp
2010 Microsoft MVP (Access)

II

http://www.regina-whipp.com/index_files/TipList.htm

Hey, I recognize this code! <grin>
--

Ken Snell
http://www.accessmvp.com/KDSnell/


Hi Gina -
I am searching away on my side to see if I can find anything that may
help out.  I will have to check out a few more websites once I get
home.
I do have a code that I use in another database, though the purpose is
different.  Maybe some of the code might give you an idea.
The code creates dummy queries for each individual managerID and then
exports a xls file for each managerID.  I cannot tell you everything
that the code is doing, but I know that it looks at a managerID table
in the database and adds the managerID field to the name of the
exported file and moves to the next one.  Just thought it may possibly
help, or not.

Dim dbs As DAO.Database
Dim rstMgr As DAO.Recordset, rstMgr1 As DAO.Recordset
Dim strSQL As String, strTemp As String, strMgr As String
Dim strPathFile As String, strFile As String, strPath As String
Dim strTable As String, strBrowseMsg As String
Dim blnHasFieldNames As Boolean
strBrowseMsg = "Select the folder where the detail files will be
created:"
strPath = BrowseFolder(strBrowseMsg)
If strPath = "" Then
MsgBox "No folder was selected.", vbOK, "No Selection"
Exit Sub
End If
Const strQName As String = "zExportQuery"
Set dbs = CurrentDb
' Create temporary query that will be used for exporting data;
' we give it a dummy SQL statement initially (this name will
' be changed by the code to conform to each manager's identification)
strTemp = dbs.TableDefs(0).Name
strSQL = "SELECT * FROM [" & strTemp & "] WHERE 1=0;"
Set qdf = dbs.CreateQueryDef(strQName, strSQL)
qdf.Close
strTemp = strQName
' *** code to set strSQL needs to be changed to conform to your
' *** database design -- ManagerID and EmployeesTable need to
' *** be changed to your table and field names
' Get list of ManagerID values -- note: replace my generic table and
Field names
' with the real names of the EmployeesTable table and the ManagerID
Field
strSQL = "SELECT DISTINCT Subinventory FROM [Subinv Subtotal By
Transaction Type];"
Set rstMgr = dbs.OpenRecordset(strSQL, dbOpenDynaset, dbReadOnly)
' Now loop through list of ManagerID values and create a query foreach
ManagerID
' so that the data can be exported -- the code assumes that the actual
names
' of the managers are in a lookup table -- again, replace generic
names with
' real names of tables and fields
If rstMgr.EOF = False And rstMgr.BOF = False Then
rstMgr.MoveFirst
Do While rstMgr.EOF = False
' *** code to set strMgr needs to be changed to conform to your
' *** database design -- ManagerNameField, ManagersTable, and
' *** ManagerID need to be changed to your table and field names
' *** be changed to your table and field names
strMgr = DLookup("Subinventory", "Stores for Export", _
' *** code to set strSQL needs to be changed to conform to your
' *** database design -- ManagerID and EmployeesTable need to
' *** be changed to your table and field names
strSQL = "SELECT * FROM [Subinv Subtotal By Transaction
Type] WHERE " & _
Set qdf = dbs.QueryDefs(strTemp)
qdf.Name = "q_" & strMgr
strTemp = qdf.Name
qdf.SQL = strSQL
qdf.Close
Set qdf = Nothing
strFile = Format$(Date, "Medium Date") & " " & strMgr &
  Ken Snell replied to Gina Whipp
06-Feb-10 10:48 PM
Yeah, I'd read that in his first post. Erick C and I had a long thread for
getting that code defined a few months back. <smile>

Thanks, Erick, for the mention!

Haven't had much time lately to prowl the newsgroups.....
--

Ken Snell
http://www.accessmvp.com/KDSnell/
  Gina Whipp replied to Ken Snell
06-Feb-10 11:32 PM
You are missed!

--
Gina Whipp
2010 Microsoft MVP (Access)

II

http://www.regina-whipp.com/index_files/TipList.htm

Yeah, I'd read that in his first post. Erick C and I had a long thread for
getting that code defined a few months back. <smile>

Thanks, Erick, for the mention!

Haven't had much time lately to prowl the newsgroups.....
--

Ken Snell
http://www.accessmvp.com/KDSnell/
  Ken Snell replied to Gina Whipp
06-Feb-10 11:45 PM
Thanks, I do appreciate your note!
--

Ken Snell
http://www.accessmvp.com/KDSnell/
Create New Account
help
UserName MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf" Set Maildb = Session.GETDATABASE("", MailDbName) If Maildb.ISOPEN = True Then Else Maildb.OPENMAIL End If Set MailDoc = Maildb.CREATEDOCUMENT Modules DAO Discussions MailDoc.CREATERICHTEXTITEM (1) MailDoc.SAVEMESSAGEONSEND (1) Maildb.CREATEDOCUMENT (1) AttachME.EMBEDOBJECT (1) Session.GETDATABASE (1) Maildb.OPENMAIL (1) Maildb.ISOPEN (1) MailDoc.PostedDate (1) Okay I figured everything out
snp", Access Discussions MailDoc.CREATERICHTEXTITEM (1) MailDoc.SAVEMESSAGEONSEND (1) Maildb.CREATEDOCUMENT (1) AttachME.EMBEDOBJECT (1) Session.GETDATABASE (1) Maildb.OPENMAIL (1) You do not change that particular line of code to accomodate UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf" 'Open the mail database in notes Set Maildb = Session.GETDATABASE("", MailDbName) If Maildb.IsOpen = True Then 'Already open for mail Else Maildb.OPENMAIL End If
As Object Dim datetime As NotesDateTime i = 0 Set session = CreateObject("Notes.NotesSession") Set notesdb = session.GetDatabase("Server", "path \ file.nsf") 'Check if open If notesdb.IsOpen = True Then Else notesdb.OPENMAIL