Private Sub Command164_Click()
On Error GoTo ErrorHandler
Dim myCurrentDir As String
Dim myReportOutput As String
Dim myMessage As String
myCurrentDir = CurrentProject.Path & "H:\"
myReportDir = myCurrentDir & "Reports" & "\"
myReportOutput = myReportDir & "past due invoices" & ".pdf"
DoCmd.OutputTo acOutputReport, [rptpastdueinvoicesreport].[past due], _
acFormatPDF, myReportOutput, , , , acExportQualityPrint
myMessage = "Report generated inside " & myReportDir
MsgBox myMessage, vbInformation
On Error Goto ErrorHandler
Dim strPath as string
strPath="H:\Reports\PastDueInvoices.pdf"
DoCmd.OutputTo acOutputReport, "Past Due", acFormatPDF, strPath, , , , acExportQualityPrint
Exit:
Exit Sub
ErrorHandler:
Msgbox "There was an error export the report to " & strPath
resume exit
End Sub
Msgbox mycurrentdir
Private Sub Command164_Click()
On Error GoTo ErrorHandler
Dim strReportPath As String
Const strReportDir As String = "C:\users\hmartinez\desktop\Reports\"
strReportPath = strReportDir & "Past Due Invoices List_" & Me.[[COLOR=Red]ProjectNumber[/COLOR]] & ".pdf"
DoCmd.OutputTo acOutputReport, rptpastdueinvoicesreport, _
acFormatPDF, strReportPath, , , , acExportQualityPrint
MsgBox "Report generated inside " & strReportDir, vbInformation
Done:
Exit Sub
ErrorHandler:
MsgBox Error$
Resume Done
End Sub
Public Function Exist(ByVal strPath As String, Optional lngAttribute As Long) As Integer
'attributes are
'vbNormal 'vbreadonly 'vbhidden 'vbSystem 'vbVolume vbdirectory 'vbalias
'see this for more detail on attributes [url]http://www.techonthenet.com/access/functions/file/dir.php[/url]
On Error Resume Next
Exist = Len(Dir(strPath, lngAttribute)) > 0
End Function
Public Sub ExportPDF(strRoot As String, strAddress As String, strProjectNumber As Long, rpt As String)
On Error GoTo Err_Handler
Dim strPath As String
'Root directory of your file
strPath = strRoot & "\" & strProjectNumber & "\"
Dim strFile As String
'Full address of your file
strFile = strPath & strProjectNumber & " " & strAddress
'Does the directory exist? If not, create it
If Exist(strPath, vbDirectory) = 0 Then MkDir (strPath)
'Does the file exist?
If Exist(strFile) Then
Dim intResponse As Integer
intResponse = MsgBox("That file already exists! Would you like to replace it?", vbYesNo, "Error")
If intResponse = vbYes Then
Kill (strFile)
Else
Exit Sub
End If
End If
DoCmd.OutputTo acOutputReport, rpt, acFormatPDF, strFile, , , , acExportQualityPrint
Exit_Sub:
Exit Sub
Err_Handler:
MsgBox Err.Number & " " & Err.Description
Resume Exit_Sub
End Sub
Private Sub Command77_Click()
call ExportPDF("C:\YourRootFolderHere",me.YourAddressField,Me.YourProjectNumberField, "YourReportName")
end sub