locked
Access VBA - Test for path, create if needed and print to a PDF RRS feed

  • Question

  • I have DB that creates Invoices and my client is manually printing to a PDF. This needs to be automatically down.

    I've searched through the net and found code to test for and create the path and I've found some code to auto print to PDF on a fixed path but it needs to be to the tested path above.Any suggestions would be appreciated.

    Monday, November 9, 2015 11:30 AM

All replies

  • Print in the fixed path and then move the archive to wherever you want.

    I use pdfcreator command line to do this.


    Monday, November 9, 2015 12:29 PM
  • Sorry but having to move the file once printed to PDF is what I need to overcome.

    Thanks anyway.

    Monday, November 9, 2015 12:35 PM
  • I don't use Access but I do use PDFCreator and it allows you specify the output path in the command line.

          cmd = """" & "C:\Program Files\PDFCreator\PDFCreator.exe" & """" & " /IF" & """" & outFilePS & """" & " /OF" & """" & outFilePDF & """"
    

    Monday, November 9, 2015 1:01 PM
  • Thanks but that is a hard coded path which would have to be changed every month.
    Monday, November 9, 2015 1:24 PM
  • I think I understand what you are asking.  Here is a sample of something that will test for a folder and create it if it doesn't exist.  I set the folder name to yyyy_mm using the current date.  You need to add a reference to the 'Microsoft Scripting Runtime'.

    Sub test()
      Dim fso As New Scripting.FileSystemObject
      Dim curDir As String
      Dim yr As String
      Dim mon As String
      Dim myFolder As String
      
      yr = Year(Date)
      mon = Right("0" & Month(Date),2)
      curDir = yr & "_" & mon
      myFolder = "C:\MyInvoices\" & curDir
      
      
      If Not fso.FolderExists(myFolder) Then
        fso.CreateFolder (myFolder)
      End If
      
      ' Write pdf to folder.
        
    End Sub

    Monday, November 9, 2015 3:25 PM
  • Thanks.

    I'll try this.

    Monday, November 9, 2015 5:41 PM