Results 1 to 6 of 6
  1. #1
    Delta729 is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Location
    Los Angeles
    Posts
    95

    How do I save a report to PDF in folder matching values of listbox

    First of all, I barely use Access and I'm very much a novice so I hope I explain this correctly so it makes sense.

    I have a very small database created just for the purpose of easy formatting a report and printing the report to PDF for management. I have everything set up and everything is working great, except I would like to be able to route the report when saving to a folder based on the values of list boxes.

    I have a form with 3 list boxes that cascade or depend on values on the preceding one. The first box is "lstDivision", when selected it drills down and shows the values for "lstDivRep" and 3rd is "lstAssociate". I currently have all of the files so they will save to PDF in a local folder. What I'd like to do is set this up so it will route to sub-folders based on the values selected in the first two list boxes. (Hope this makes sense). The "lstAssociate" is multi-selection list box.

    Here is the code I have now:

    Private Sub btnSaveToPDF_Click()

    Dim sReportName As String
    sReportName = "IDP" '' name of the predefined report

    Dim vItm As Variant
    Dim sSQL As String

    For Each vItm In [Forms]![IDP]![lstAssociate].ItemsSelected
    sSQL = "[Associate] = '"
    sSQL = sSQL & [Forms]![IDP]![lstAssociate].ItemData(vItm) & "'"

    DoCmd.OpenReport sReportName, acViewPreview, , sSQL

    DoCmd.OutputTo acOutputReport, "", acFormatPDF, "C:\Users\Daniel\Desktop\backup copy\New Output\" & [Forms]![IDP]![lstAssociate].ItemData(vItm) & " - " & [Forms]![IDP]![lstDivision].ItemData(vItm) & " - Updated (" & Format(Date, "mm-dd-yyyy") & ")" & ".PDF", False

    DoCmd.Close acReport, sReportName
    Next vItm

    End Sub




    Any help would be greatly appreciated because I've been searching off and on for 3 days.

    Thanks, Dan

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    What is the issue? What happens when the code runs - error message, wrong results, nothing?

    Do the folders at each level already exist? If not, will have to run code that creates them.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Delta729 is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Location
    Los Angeles
    Posts
    95
    Hi June,

    The code run's perfectly and puts all of the PDFs into one folder New Output. Basically, there are about 200 associates and the way this works now putting all the PDFs into one folder, I'd have to manually move them after they've been saved to the New Output folder. What I'd like to be able to do is to automatically look at the value selected in the first list box "lstDivision" and the second list box "lstDivRep" and put these into existing sub-folders in the folder called New Output. I hope that makes sense.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    If the folders already exist then modify your path concatenation to include the listbox values for those folders.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Delta729 is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Location
    Los Angeles
    Posts
    95
    That is where I'm completely lost. I should have said I'm a complete novice "idiot" at Access & especially VBA. It took me over a week to get this code working that I had found on the web. Do I need to declare the listbox for their selected values? Like the Dim sReportName As String (or variant) is on the code right now?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    No, listbox is a variable, just refer to the listbox. Actually looks like your code is already doing that except need to concatenate "\" between each folder variable and the filename. Replace " - " with "\".
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. How to save report as PDF in certain folder
    By kassem in forum Programming
    Replies: 4
    Last Post: 06-04-2014, 07:42 AM
  2. Browse and Open Folder Based on Matching Form Field
    By Tomfernandez1 in forum Access
    Replies: 11
    Last Post: 02-26-2013, 01:04 PM
  3. Save report to a folder
    By Gilgamesh in forum Programming
    Replies: 2
    Last Post: 12-23-2012, 07:25 PM
  4. Replies: 4
    Last Post: 09-18-2012, 11:30 PM
  5. Replies: 9
    Last Post: 01-20-2011, 02:22 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