Export to PDF Question

all7holly

Registered User.
Local time
Today, 10:11
Joined
Nov 16, 2011
Messages
49
Below is VBA I have used to create a folder, convert the file into PDF and name it. I would like to know what lines I need to remove to not create the floder, because I want to send it to a folder that already exists.
Private Sub SendToKatieFolder_Click()
Call ExportPDFINVOICEkatiefolder("C:\Users\hmartinez\Desktop\Katie Weekly Sent Invoices", Me.PropertyAddress, Me.ProjectNumber, Me.InvoiceNumber, Me.BillingCompany, "rptinvoice")
End Sub

Public Sub ExportPDFINVOICEkatiefolder(strRoot As String, strPropertyAddress As String, strprojectnumber As String, strInvoiceNumber As Long, strBillingCompany As String, rpt As String)
On Error GoTo Err_Handler
Dim strPath As String
'Root directory of your file
strPath = strRoot & "\" & strprojectnumber & " " & strPropertyAddress & "\"
Dim strFile As String
'Full address of your file
strFile = strPath & "Invoice" & " " & strInvoiceNumber & " " & strBillingCompany & " " & strPropertyAddress & " " & "Project Number" & " " & strprojectnumber & ".pdf"
'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
 
See in red. You need to change this so it does what you want it to do if the folder doesn't exist. If you aren't creating it than you need to exit the routine or do something else.

Code:
Public Sub ExportPDFINVOICEkatiefolder(strRoot As String, strPropertyAddress As String, strprojectnumber As String, strInvoiceNumber As Long, strBillingCompany As String, rpt As String)
On Error GoTo Err_Handler
Dim strPath As String
'Root directory of your file
strPath = strRoot & "\" & strprojectnumber & " " & strPropertyAddress & "\"
Dim strFile As String
'Full address of your file
strFile = strPath & "Invoice" & " " & strInvoiceNumber & " " & strBillingCompany & " " & strPropertyAddress & " " & "Project Number" & " " & strprojectnumber & ".pdf"
'Does the directory exist? If not, create it
[COLOR=red]If Exist(strPath, vbDirectory) = 0 Then MkDir (strPath)[/COLOR]
'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
 
You wouldn't need to change anything. Your code already won't create the folder if it already exists.
 
I is creating a folder inside the folder that already exists. I want it to just send the file to the existing folder on my desktop.
 
I is creating a folder inside the folder that already exists. I want it to just send the file to the existing folder on my desktop.

Then you need to change this to remove the parts in red

'Root directory of your file
strPath = strRoot & "\" & strprojectnumber & " " & strPropertyAddress & "\"


and change what you pass as strRoot when you call that procedure.
 
So you don't want to create the property address and property number folder? You just want the file to be saved directly to this folder: C:\Users\hmartinez\De sktop\Katie Weekly Sent Invoices
 
The file path is below.

C:\Users\hmartinez\Desktop\Katie Weekly Sent Invoices
 
It is an existing folder. The file just needs to be sent to that existing folder.
 
It is an existing folder. The file just needs to be sent to that existing folder.

Okay, change this:
'Root directory of your file
strPath = strRoot & "\" & strprojectnumber & " " & strPropertyAddress & "\"

to this

'Root directory of your file
strPath = "C:\Users\" & Environ("username") & "\Desktop\Katie Weekly Sent Invoices
 
Like Bob said you need to change this line:

strPath = strRoot & "\" & strprojectnumber & " " & strPropertyAddress & "\"

to this:

strPath = strRoot & "\"
 
Last edited:

Users who are viewing this thread

Back
Top Bottom