Results 1 to 4 of 4
  1. #1
    ecalvert47462 is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2011
    Posts
    17

    Saving an Access Report, as a PDF, to my desktop

    Hello All,
    So I recently wanted to know how I could save an access report, as a PDF, to my computer's desktop at the push of a button...and I did, also got it to add today's date as well. After searching the internet I found the below code and it works great, here is the code I use:
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Private Sub Command2_Click()
    On Error GoTo Err_Command2_Click
    Dim stDocName As String
    Dim stReportPathName As String
    stDocName = "Sales Report By Area"

    stReportPathName = "C:\Users\" & Environ("UserName") & "\Desktop\Sales Report By Area " & Format(Date, "mm-dd-yyyy") & ".pdf"

    DoCmd.OpenReport stDocName, acViewPreview, , acHidden



    DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, stReportPathName, , True

    DoCmd.Close acReport, "Sales Report By Area", acSaveNo

    MsgBox "Report has been saved to Desktop"

    Exit_Command2_Click:
    Exit Sub
    Err_Command2_Click:
    MsgBox Err.Description
    Resume Exit_Command2_Click
    End Sub
    -------------------------------------------------------------------------------------------------------------------------------------------------------
    So now that I got that down I want to be able to do one more thing. I have some reports that based on a combobox selection I make will then run the report and spit out the results. I want to be able to do the exact same thing with those reports but also put the selection that I made (from my combobox) in the report name when it's saved to my desktop.
    For example, let's say I go to my form and select the area that I want from the combobox....let's say I select "Northwest"....How would I get my selection of "Northwest" to fall into the report name/date (like was done in code above) so it would automatically all be one title like:
    Sales Report By Area - Northwest 12-15-14
    What would I need to add to the above code to make that happen?
    Thanks,
    Eric

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Concatenate the combobox into the string just like referencing any variable.

    ... & Me.comboboxname & Format(...
    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
    ecalvert47462 is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2011
    Posts
    17
    so just put the ...& Me.comboboxname...right before i go into the formate(date...part of it?
    wow, that seems super easy. I'll give it a shot tomorrow and see if it works.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Wait, that was assuming value of combobox is actually the descriptive text "Northwest". If the value is actually an ID from a lookup table, code will have to reference the column that has "Northwest". Is the combobox multi-column? Reference combo and list box columns by their index. Index begins with 0.
    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. Replies: 1
    Last Post: 11-05-2014, 05:35 PM
  2. Replies: 4
    Last Post: 08-21-2013, 07:08 AM
  3. Using Access on a Mac through Remote Desktop
    By philsonghurst in forum Misc
    Replies: 3
    Last Post: 06-24-2012, 11:10 AM
  4. Access and Remote Desktop
    By pedsys in forum Access
    Replies: 1
    Last Post: 10-08-2010, 10:42 AM
  5. Replies: 2
    Last Post: 09-29-2009, 10:25 AM

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