Full Version: In A Pickle With My Pdf Code
UtterAccess Discussion Forums > Microsoft® Access > Access Reports
MikeGSuppe
Greetings

I am trying to automate our invoicing. The tricky bit is that each client has their own directory, plus we always put everything into years. The the full path for each invoice would be say;
C:\Users\RB\Documents\AA All Companies\JJH\Export Documents\ClientA\2012
then for another clients it would be
C:\Users\RB\Documents\AA All Companies\JJH\Export Documents\ClientF\2012
etc


The concept is to store the individual folder location in a field in the table and then call that field when I query the name of the client being invoiced. It is obvious that I have made an error in the way I am trying to setup the variables to combine them together to make the full location and file name.

My code thus far ;


Private Sub btn_PDFInv_Disc_Click()
Dim myPath As String
Dim myPathName As String
Dim myPathDest As String
Dim strReportName As String
Dim strDocName As String
Dim strLinkCriteria As String


strDocName = "rpt_JJH_ExportInvoice_Discount"
strLinkCriteria = "[INVOICENUMBER] = Forms![frm_JJH_Data_Export_SalesData]![INVOICENUMBER]"

myPath = "C:\Users\RB\Documents\AA All Companies"
myPathName = [Forms]![frm_JJH_DATA_Export_SalesData]![cboClientID].Column(3)
myPathDest = myPathName & " \ "

strReportName = [Forms]![frm_JJH_DATA_Export_SalesData]![INVOICENUMBER] & " - " & [Forms]![frm_JJH_DATA_Export_SalesData]![CLIENTORDERNUMBER] & " .pdf"

DoCmd.OpenReport strDocName, acViewPreview, , strLinkCriteria

DoCmd.OutputTo acOutputReport, strDocName, acFormatPDF, myPath + myPathDest + strReportName, False

Forms![frm_JJH_DATA_Export_SalesData].[PRINTED] = "Yes"
DoCmd.Close acReport, strDocName


It is frustration me as I can do this is I set the full path in the mypath string but due to the variables each pdf file has to go to the individual companies own folder.

thanks

~mike
Alan_G
Hi

Wouldn't it be something like

CODE
myPath = "C:\Users\RB\Documents\AA All Companies\" & [Forms]![frm_JJH_DATA_Export_SalesData]![cboClientID].Column(3) _
& "\" & Year(Date()) & "\" &  strReportName

DoCmd.OutputTo acOutputReport, strDocName, acFormatPDF, myPath, False

MikeGSuppe
Hi Alan

It still gives me the 2501 error message - that the output was cancelled?

It works well and I have check under debug.print that it does show the correct directory to put the file to.

`mike
Alan_G
Hi

Does the directory you want to save to already exist before you try and save your file there ? You could check that with

CODE
Dim strDirPath As String

strDirPath = "C:\Users\RB\Documents\AA All Companies\" & [Forms]![frm_JJH_DATA_Export_SalesData]![cboClientID].Column(3) _
& "\" & Year(Date())

If Len(Dir(strDirPath ,vbDirectory)) > 0 Then
   'directory exists so go ahead and save your file
   Else
   'directory doesn't exist so it needs creating first
End If


Also, don't know whether it's a typo or not, but you seem to have a space between the dot and the pdf extender (ie & " .pdf"). If it is a space, then try getting rid of it so it's just .pdf
MikeGSuppe
Hi Alan

Thanks for some reason doing the .pdf seemed to fix it

~rolf
Alan_G
Hi

Yep, if it was a space you had there it would have caused the problem. Glad you're sorted thumbup.gif
GlenKruger
Good eyes Alan I didn't see that till you pointed it out.

The reason it didn't work with the space included in the quotes is that is was looking for a file name and a space before the .pdf which it could not find.
Alan_G
QUOTE
Good eyes Alan


Nah.........new glasses laugh.gif
GlenKruger
I go on the 6th of June for hopefully a new pair.

May or may not help laugh.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.