Results 1 to 9 of 9
  1. #1
    tonek22 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2015
    Posts
    5

    export report to multiple PDF files and multiple directories using field names

    Hallo, can anyone help me. I have to admit that I am not experienced in programing and my english is also not excelent. I need to export my report, into multiple PDF files based on field "sampleID", and those PDF files I need to get to different directories based on field "village". I have approximately 6 thousand of objects and about hundred of villages. It is almost impossible to do this manually. I allready used script from one of threads placed on this forum. here. I mannaged to change it for myself. it is working fine, but all PDF files are stored in one place.



    I dont know how can I add this "village" into path (in DoCmd.OutputTo?) to achieve exporting reports based on sampleID in its subdirectory based on village. If anyone can help me, I would be very grateful.

    Code:
    Option Compare Database
    
    Private Sub cmd_cz__rozsirene_Click()
    Dim MyDB As DAO.Database
    Dim MyRS As DAO.Recordset
    Dim strSQL As String
    Dim strRptName As String
    Dim count As Integer
    
    strRptName = "Cz_Tisk_rozsirene"
    strSQL = "Select q_filtrCzTisk_rozsirene.[SampleId] From q_filtrCzTisk_rozsirene;"
    Set MyDB = CurrentDb
    Set MyRS = MyDB.OpenRecordset(strSQL, dbOpenForwardOnly)
    With MyRS
    Do While Not MyRS.EOF
    DoCmd.OpenReport strRptName, acViewPreview, , "[SampleId]='" & ![SampleId] & "'"
    DoCmd.OutputTo acOutputReport, strRptName, acFormatPDF, "C:\_pokusne\datab\" & ![SampleId] & ".pdf", False
    DoCmd.Close acReport, strRptName, acSaveNo
    .MoveNext
    Loop
    
    End With
    MyRS.Close
    Set MyRS = Nothing
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    The simple answer is, you concatenate village into the string just as you did SampleID. How is village determined? Can something be added to the recordset SQL to get it, or ?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    tonek22 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2015
    Posts
    5
    Yes, I tried but it didnt work for me. As I wrote I didnt create the code, I just changed some pieces. I dont understand the code at all.

    I tried to write something like this:
    Code:
    DoCmd.OutputTo acOutputReport, strRptName, acFormatPDF, "C:\_pokusne\datab\" & ![Village] & "\" & ![SampleId] & ".pdf", False
    after that I got runtime error - item not found in the collection

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    In the code posted, Village is not a field being returned for the recordset, so is not available for use like that. That's why I asked if it could be added to the recordset SQL.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    tonek22 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2015
    Posts
    5
    I guess yes, it can be added, but I dont know how. is itt possible that you write this one row of code for me? please?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    I don't know your data structure. You can try this:

    strSQL = "Select q_filtrCzTisk_rozsirene.[SampleId], Village From q_filtrCzTisk_rozsirene;"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    tonek22 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2015
    Posts
    5
    Hi, sorry I didn't reply yesterday.

    I've tried to use your advice. This happend.

    runtime error 2501 - OutputTo event has been canceled

    Code:
    Option Compare Database
    
    Private Sub cmd_cz__rozsirene_Click()
    Dim MyDB As DAO.Database
    Dim MyRS As DAO.Recordset
    Dim strSQL As String
    Dim strRptName As String
    Dim count As Integer
    strRptName = "Cz_Tisk_rozsirene"
    strSQL = "Select q_filtrCzTisk_rozsirene.[SampleId], q_filtrCzTisk_rozsirene.[Village] From q_filtrCzTisk_rozsirene;"
    Set MyDB = CurrentDb
    Set MyRS = MyDB.OpenRecordset(strSQL, dbOpenForwardOnly)
    With MyRS
    Do While Not MyRS.EOF
    DoCmd.OpenReport strRptName, acViewPreview, , "[SampleId]='" & ![SampleId] & "'"
    DoCmd.OutputTo acOutputReport, strRptName, acFormatPDF, "C:\_pokusne\datab\" & ![Village] & "\" & ![SampleId] & ".pdf", False
    DoCmd.Close acReport, strRptName, acSaveNo
    .MoveNext
    Loop
    
    End With
    MyRS.Close
    Set MyRS = Nothing
    End Sub
    if I delete "\" in outputfile and try to export - it is working, but name of village appears in the name of file.
    My problem is how to write the code to achieve creating subdirectorie using village field. Any Ideas?

    Anyway I am gratefull for your help. Thank You.

  8. #8
    tonek22 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2015
    Posts
    5
    now I find out, that if there exist subfolder with name of village from my report, export will be done. Unfortunately in case when there is no subfolder , this code stops generating PDF files.

    Do You have any Idea how can I solve this hopefully last problem?

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    You can use Len() and Dir() to test, MkDir() to create.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 10
    Last Post: 09-17-2014, 08:23 AM
  2. Export one query to multiple Excel files
    By bliffer in forum Import/Export Data
    Replies: 3
    Last Post: 01-29-2014, 02:37 PM
  3. Import / Export Multiple Files & Tabs
    By maggiemago3 in forum Programming
    Replies: 6
    Last Post: 08-21-2013, 11:20 AM
  4. Replies: 11
    Last Post: 12-20-2012, 12:30 PM
  5. Export Access into multiple excel files based on field value
    By turntabl1st in forum Import/Export Data
    Replies: 7
    Last Post: 11-08-2012, 12:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums