Results 1 to 5 of 5
  1. #1
    alyon is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    89

    Help Send Report to File.

    I can't figure out how to get my command button to send my report to the folder I want. Here is the code I originally used, and kept getting run time error 2501:

    Dim MyPath As String
    Dim MyName As String

    MyPath = "\\Folder\Reports"
    MyName = Me.txtDate.Value

    DoCmd.OpenReport "Final Report", acViewPreview, , "[ID] = " & Me.[ID]
    DoCmd.OutputTo acOutputReport, "Final Report", acFormatPDF, MyPath & MyName, True
    DoCmd.Close acReport, "Final Report"

    So, then I tried:

    DoCmd.OpenReport "Final Report", acViewPreview, , "[ID] = " & Me.[ID]


    DoCmd.OutputTo acOutputReport, "Final Report", acFormatPDF, "\\Folders\Reports" & Me.txtDate, True
    DoCmd.Close acReport, "Final Report"

    which also gave me a runtime error 2501.

    I finally narrowed the issue down to exactly the folder/name, so I tried no name, and multiple different folders, and none of it would work. I tried it in macro instead of vba, and that still gave me a runtime error, just a different one..

    So finally I ended up with this:

    DoCmd.OpenReport "Final Report", acViewPreview, , "[ID] = " & Me.[ID]
    DoCmd.OutputTo acOutputReport, "Final Report", acFormatPDF, "Final Report", True
    DoCmd.Close acReport, "Final Report"

    which is the only code so far to not give a runtime error, and to actually save it somewhere.... but, the problem is I don't get to pick where I save it, and they all come up with the same name so only one can save itself in that folder at a time..


    Any help would greatly be appreciated.
    Thank you in advance!
    A Lyon

  2. #2
    apr pillai's Avatar
    apr pillai is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2010
    Location
    Alappuzha, India
    Posts
    209
    It looks like you are trying to save the file in a Server path; you are using a UNC type address for the folder. Try after modifying the following line as given below:


    Code:
    MyPath = "\\ServerName\Folder\Reports\"
    After the folder name ....\Report there should be a back-slash as given above. Replace the ServerName text with the correct Server Name.

  3. #3
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Hi alyon,

    I just created a Form and used a command button with pretty much your code to save one of my reports to my C: drive. No problem.

    Here's what I used:
    Code:
     
    Dim MyPath, MyName As String
     
    MyPath = "C:\"
    MyName = "ReportName.pdf"
     
    DoCmd.OutputTo acOutputReport, "MYReport", acFormatPDF, MyPath & MyName, True
    Let me know if this helps!

  4. #4
    alyon is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    89
    I am trying to save it in a server path :] I added the backslash and still can't get it to work. I also tried Robeen's suggestion, and that didn't even work. :/ I just keep getting the runtime error 2501. :|
    Here is my exact code (with the exception that I used 'server' for the network name), thank you both for the suggestions, do you see anything else that might be wrong?

    Private Sub cmdFile_Click()
    Dim strMyPath As String
    Dim strMyName As String

    strMyPath = "\\Server\Server Main\Final Result\"
    strMyName = Me.txtDate.Value

    DoCmd.OpenReport "Final Result Report", acViewPreview, , "[ID] = " & Me.[ID]
    DoCmd.OutputTo acOutputReport, "Final Result Report", acFormatPDF, strMyPath + strMyName, True
    DoCmd.Close acReport, "Final Result Report"
    End Sub

  5. #5
    alyon is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    89
    Waittt!!! I got it!! I changed txtDate to cboJobName for the name of the report and it works!!! Thank you both!! It was definitely the backslash giving me all the difficulties with saving it to the network.

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

Similar Threads

  1. How to send filtered report via email
    By degras in forum Reports
    Replies: 4
    Last Post: 03-31-2011, 09:09 AM
  2. HELP! how to send data from table to text file
    By daveofgv in forum Import/Export Data
    Replies: 11
    Last Post: 02-14-2011, 01:22 AM
  3. send object report
    By ldappa in forum Access
    Replies: 1
    Last Post: 07-19-2010, 10:10 AM
  4. Send Primary Key from a Form To A Report
    By nkuebelbeck in forum Forms
    Replies: 1
    Last Post: 03-18-2010, 12:24 PM
  5. Replies: 0
    Last Post: 10-04-2009, 04:11 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