1. what kind of button should I use on the custom tool bar and that button
Any kind of button. Set the OnAction to "=FunctionName()"
2. you said 'supply name of the report to LeBans function. but I want that
button to take care of any previewed report. Looks like I need a variable?
how to use variable to refer to the last previewd report?
It depends on what you want to do. Do you want to PDF the Active
report? Do you want to PDF the last opened and currently open report
(whether or not it is active)? Do you want to PDF the most recently
opened report that is currently closed?
The code in this post will take care of the Active report. It would be
easy to modify to take care of the last opened and not necessarily
active report (with the Reports() collection). I think you will need
to come up with a solution if what you want is the most recent closed
report - ouch.
That said, here is my code that, when placed on a custom toolbar,
exports the active report as PDF:
Option Compare Database
Option Explicit
'OnAction of a toolbar button should be set to
"=ExportOpenReportToPDF()"
'This will output the report as a snapshot and call Lebans' function
to convert
'the snapshot to PDF.
Public Function ExportOpenReportToPDF()
Dim blRet As Boolean
If Application.Reports.Count > 0 Then
'Clear out temp file
If safeKill(getTempSNPFile()) Then
'Leaving the 2nd argument blank exports the Active object
'(You will want to disable this function for Forms, etc.)
'This will create a snapshot file
DoCmd.OutputTo acOutputReport, , acFormatSNP,
getTempSNPFile(), False
'Clear out temp file
If safeKill(getTempPDFFile()) Then
blRet = ConvertReportToPDF(, getTempSNPFile(),
getTempPDFFile(), False, False)
End If
'Call your e-mail functions here
End If
'Remove temp files - commented so that we can see the output.
'call safekill(gettemppdffile())
'call safekill(gettempsnpfile())
End If
End Function
'Just like kill only minimizes error handling in the calling function
Private Function safeKill(strFileName As String) As Boolean
On Error GoTo safeKill_Err
If Dir(strFileName) <> "" Then Kill strFileName
safeKill = True
Exit Function
safeKill_Err:
safeKill = False
End Function
'The path/filename of the temp file we use
Private Function getTempSNPFile() As String
getTempSNPFile = CurrentProject.path & "\" & "MyTempSNP.snp"
End Function
'The path/filename of the temp file we use
Private Function getTempPDFFile() As String
getTempPDFFile = CurrentProject.path & "\" & "MyTempPDF.PDF"
End Function
3. yes outlook is the default mail client
Please look at another post of mine. Modify the code as desired
(simplify it) to send the e-mail as an attachment w/ outlook:
http://groups.google.com/group/micr...s/browse_thread/thread/3dd8386d1f0cf641?tvc=2