Access reports in separate PDFs, in separate Folders.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • provokatori
    New Member
    • Nov 2013
    • 4

    Access reports in separate PDFs, in separate Folders.

    Dears,
    I have a table where I have ProjectName, City and etc. I want from Access to spit out in separate files pdf files for every City in every ProjectName folder.
    Can I have rough idea on how to do it :(. Right now what I have is this. Which is spitting One folder one file by City. So they change their mind and now requiered from me by project where every project has in separate pdf files for each city

    Code:
    Do While Not rst2.EOF
                   ktrcode = rst2![ParentID]
                   agreement = Mid(rst2![Project], 13, 6)
                            
    ProjectPath = "C:\CachePDF" & "\" & ktrcode & "\Project\" & "Project" & rst2![ProjectCode] & " " & Format(rst2![GenDate] - 1, "yyyy.mm.dd") & ".pdf"
                            
                            
     If Len(Dir("c:\CacheCDRPDF\" & ktrcode & "\Project\", vbDirectory)) = 0 Then
     MkDir "c:\CacheCDRPDF\" & ktrcode & "\Project\"
    End If
                            
                                                   
     strRptFilter = "[Project Number] = '" & rst2![ProjectName] & "' AND [City] = '" & Me.txtCityNAC & "'"
                            
    DoCmd.OutputTo acOutputReport, "rptProjectDaily", acFormatPDF, ProjectPath
    I would appreciate any help I just messing around and could not get any desired result
    Last edited by provokatori; Nov 22 '13, 05:13 AM. Reason: Tried to explain better :(
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    What are you getting?

    Line 5: you have "yyyy.mm.dd " as the date format. On my network, IT has the antivirus automatically quarentine any file that has a multiple periods in the name as that is how many virus in the past tried to hide.

    Line13: Very carfully check this, you have [project number] and yet pulling from RST2![ProjectNAME]
    I also do not see where you are using this string.

    Comment

    • provokatori
      New Member
      • Nov 2013
      • 4

      #3
      Here is all the code.
      Line 5: doesnt matter its working with me you can just ignore the date formating
      Line 13: I`m sorry I didnt want to copy paste so I thought you could understand :( what I want with that piece of data here we go full of it.

      All I need to do right now instead of doing one file for all the cities in each Work Folder(Project) , I need to do All cities in separate files in Work Folder.


      Code:
      Private Sub cmdCreatePdf_Click()
      Dim Cashlocation As String
      Dim agreement As String
      Dim ktrcode As String
      
      If Len(Dir("c:\CachePDF", vbDirectory)) = 0 Then
                      MkDir "c:\CachePDF"
                  End If
                  
                  'Clear Temporary Folder Structure
                  Dim FSO As Object
                  
                  Dim MyPath As String
                  Set FSO = CreateObject("scripting.filesystemobject")
                  MyPath = "C:\CachePDF"
                  If Right(MyPath, 1) = "\" Then
                      MyPath = Left(MyPath, Len(MyPath) - 1)
                  End If
                  If FSO.FolderExists(MyPath) = False Then
                      MsgBox MyPath & " doesn't exist"
                      Exit Sub
                  End If
                  'Delete files
                  FSO.DeleteFile MyPath & "\*.*", True
                  'Delete subfolders
                  FSO.DeleteFolder MyPath & "\*.*", True
      Set rst = CurrentDb.OpenRecordset("SELECT DISTINCT [Work], [GenDate], [ParentID] FROM [tblCash] WHERE (([City]) = '" & Me.txtCityNAC & "') ORDER BY [Work];", dbOpenSnapshot)
       If rst.RecordCount = 0 Then
                      
                      rst.Close
                      Set rst = Nothing
                      If rst.RecordCount <> 0 Then
                        Do While Not rst.EOF
                              
                              ktrcode = rst![ParentID]
                              agreement = Mid(rst![Work], 13, 6)
                              
                              Cashlocation = "C:\CachePDF" & "\" & ktrcode & "\" & "Cash " & rst![Work] & " " & Format(rst![GenDate] - 1, "yyyy.mm.dd") & ".pdf"
                              
                              If Len(Dir("c:\CachePDF\" & ktrcode & "\", vbDirectory)) = 0 Then
                                  MkDir "c:\CachePDF\" & ktrcode & "\"
                              End If
                              
                              
                              strRptFilter = "[Work] = '" & rst![Work] & "' AND [City] = '" & Me.txtCityNAC & "'"
                              
                         
                              DoCmd.OpenReport "rptCash", acViewPreview, , , acHidden
                              DoCmd.OutputTo acOutputReport, "rptCash", acFormatPDF, Cashlocation, True
                              DoCmd.Close acReport, "rptCash"
                              
      SendEmailCash
                              
                              DoEvents
                              rst.MoveNext
                              
                          Loop
                    End If
                  End If

      Comment

      Working...